Merge BaseActivity into MainActivity
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -34,6 +34,7 @@ import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.view.GravityCompat
|
||||
@@ -47,37 +48,56 @@ import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.store.data.model.SelfUpdate
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.data.providers.NetworkProvider
|
||||
import com.aurora.store.databinding.ActivityMainBinding
|
||||
import com.aurora.store.util.CertUtil.isFDroidApp
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.view.ui.commons.BaseActivity
|
||||
import com.aurora.store.view.ui.sheets.NetworkDialogSheet
|
||||
import com.aurora.store.view.ui.sheets.SelfUpdateSheet
|
||||
import com.aurora.store.view.ui.sheets.TOSSheet
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import nl.komponents.kovenant.task
|
||||
import nl.komponents.kovenant.ui.successUi
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
class MainActivity : AppCompatActivity(), NetworkProvider.NetworkListener {
|
||||
|
||||
private lateinit var B: ActivityMainBinding
|
||||
private lateinit var navController: NavController
|
||||
private lateinit var authData: AuthData
|
||||
|
||||
private var lastBackPressed = 0L
|
||||
|
||||
private val startForPermissions =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) {
|
||||
if (!it) toast(R.string.permissions_denied)
|
||||
}
|
||||
|
||||
private val gson: Gson = GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).create()
|
||||
|
||||
override fun onConnected() {
|
||||
hideNetworkConnectivitySheet()
|
||||
runOnUiThread {
|
||||
if (!supportFragmentManager.isDestroyed) {
|
||||
val fragment = supportFragmentManager.findFragmentByTag(NetworkDialogSheet.TAG)
|
||||
fragment?.let {
|
||||
supportFragmentManager.beginTransaction().remove(fragment)
|
||||
.commitAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDisconnected() {
|
||||
showNetworkConnectivitySheet()
|
||||
runOnUiThread {
|
||||
if (!supportFragmentManager.isDestroyed) {
|
||||
supportFragmentManager.beginTransaction()
|
||||
.add(NetworkDialogSheet.newInstance(), NetworkDialogSheet.TAG)
|
||||
.commitAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReconnected() {
|
||||
@@ -99,6 +119,9 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
val themeId = Preferences.getInteger(this, Preferences.PREFERENCE_THEME_TYPE)
|
||||
val accentId = Preferences.getInteger(this, Preferences.PREFERENCE_THEME_ACCENT)
|
||||
applyTheme(themeId, accentId)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
B = ActivityMainBinding.inflate(layoutInflater)
|
||||
@@ -113,7 +136,13 @@ class MainActivity : BaseActivity() {
|
||||
attachSearch()
|
||||
|
||||
if (!Preferences.getBoolean(this, Preferences.PREFERENCE_TOS_READ)) {
|
||||
askToReadTOS()
|
||||
runOnUiThread {
|
||||
if (!supportFragmentManager.isDestroyed) {
|
||||
val sheet = TOSSheet.newInstance()
|
||||
sheet.isCancelable = false
|
||||
sheet.show(supportFragmentManager, TOSSheet.TAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Check only if download to external storage is enabled*/
|
||||
@@ -295,4 +324,14 @@ class MainActivity : BaseActivity() {
|
||||
sheet.show(supportFragmentManager, SelfUpdateSheet.TAG)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
NetworkProvider.addListener(this)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
NetworkProvider.removeListener(this)
|
||||
super.onStop()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.ui.commons
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.aurora.extensions.applyTheme
|
||||
import com.aurora.store.data.providers.NetworkProvider
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_TYPE
|
||||
import com.aurora.store.view.ui.sheets.NetworkDialogSheet
|
||||
import com.aurora.store.view.ui.sheets.TOSSheet
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
|
||||
abstract class BaseActivity : AppCompatActivity(), NetworkProvider.NetworkListener {
|
||||
|
||||
protected val gson: Gson = GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).create()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
val themeId = Preferences.getInteger(this, PREFERENCE_THEME_TYPE)
|
||||
val accentId = Preferences.getInteger(this, PREFERENCE_THEME_ACCENT)
|
||||
applyTheme(themeId, accentId)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
fun askToReadTOS() {
|
||||
runOnUiThread {
|
||||
if (!supportFragmentManager.isDestroyed) {
|
||||
val sheet = TOSSheet.newInstance()
|
||||
sheet.isCancelable = false
|
||||
sheet.show(supportFragmentManager, TOSSheet.TAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun showNetworkConnectivitySheet() {
|
||||
runOnUiThread {
|
||||
if (!supportFragmentManager.isDestroyed) {
|
||||
supportFragmentManager.beginTransaction()
|
||||
.add(NetworkDialogSheet.newInstance(), NetworkDialogSheet.TAG)
|
||||
.commitAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun hideNetworkConnectivitySheet() {
|
||||
runOnUiThread {
|
||||
if (!supportFragmentManager.isDestroyed) {
|
||||
val fragment = supportFragmentManager.findFragmentByTag(NetworkDialogSheet.TAG)
|
||||
fragment?.let {
|
||||
supportFragmentManager.beginTransaction().remove(fragment)
|
||||
.commitAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
NetworkProvider.addListener(this)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
NetworkProvider.removeListener(this)
|
||||
super.onStop()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user