2021-05-12 21:51:02 +00:00
|
|
|
package com.lagradost.cloudstream3
|
|
|
|
|
|
|
|
import android.app.Activity
|
2021-05-15 23:37:42 +00:00
|
|
|
import android.content.res.Resources
|
2021-05-12 21:51:02 +00:00
|
|
|
import android.view.View
|
2021-05-18 13:43:32 +00:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2021-05-15 23:37:42 +00:00
|
|
|
import androidx.preference.PreferenceManager
|
2021-05-18 13:43:32 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.result.ResultFragment
|
2021-05-12 21:51:02 +00:00
|
|
|
|
|
|
|
object UIHelper {
|
2021-05-15 23:37:42 +00:00
|
|
|
val Int.toPx: Int get() = (this * Resources.getSystem().displayMetrics.density).toInt()
|
|
|
|
val Float.toPx: Float get() = (this * Resources.getSystem().displayMetrics.density)
|
|
|
|
val Int.toDp: Int get() = (this / Resources.getSystem().displayMetrics.density).toInt()
|
|
|
|
val Float.toDp: Float get() = (this / Resources.getSystem().displayMetrics.density)
|
|
|
|
|
2021-05-18 13:43:32 +00:00
|
|
|
fun AppCompatActivity.loadResult(url: String, slug: String, apiName: String) {
|
|
|
|
this.runOnUiThread {
|
2021-05-15 23:37:42 +00:00
|
|
|
this.supportFragmentManager.beginTransaction()
|
|
|
|
.setCustomAnimations(R.anim.enter_anim, R.anim.exit_anim, R.anim.pop_enter, R.anim.pop_exit)
|
2021-05-18 13:43:32 +00:00
|
|
|
.add(R.id.homeRoot, ResultFragment().newInstance(url, slug, apiName))
|
2021-05-15 23:37:42 +00:00
|
|
|
.commit()
|
2021-05-18 13:43:32 +00:00
|
|
|
}
|
2021-05-15 23:37:42 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 13:43:32 +00:00
|
|
|
fun Activity.getStatusBarHeight(): Int {
|
2021-05-12 21:51:02 +00:00
|
|
|
var result = 0
|
|
|
|
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
|
|
|
|
if (resourceId > 0) {
|
|
|
|
result = resources.getDimensionPixelSize(resourceId)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Activity.fixPaddingStatusbar(v: View) {
|
|
|
|
v.setPadding(v.paddingLeft, v.paddingTop + getStatusBarHeight(), v.paddingRight, v.paddingBottom)
|
|
|
|
}
|
2021-05-15 23:37:42 +00:00
|
|
|
|
|
|
|
private fun Activity.getGridFormat(): String {
|
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
return settingsManager.getString(getString(R.string.grid_format_key), "grid")!!
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Activity.getGridFormatId(): Int {
|
|
|
|
return when (getGridFormat()) {
|
|
|
|
"list" -> R.layout.search_result_compact
|
|
|
|
"compact_list" -> R.layout.search_result_super_compact
|
|
|
|
else -> R.layout.search_result_grid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Activity.getGridIsCompact(): Boolean {
|
|
|
|
return getGridFormat() != "grid"
|
|
|
|
}
|
2021-05-12 21:51:02 +00:00
|
|
|
}
|