diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index a195fbd..4cdb4f1 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,7 +5,7 @@
.onCreate()
+ context = applicationContext
+ DynamicColors.applyToActivitiesIfAvailable(this)
+ val serviceIntent = Intent(this, DownloadService::class.java)
+ bindService(serviceIntent, connection, BIND_AUTO_CREATE)
+ statusBarHeight()
}
- public static Context getContext() {
- return context;
- }
-
- public static DownloadService.DownloadBinder getDownloadBinder() {
- return downloadBinder;
+ override fun onDestroy(owner: LifecycleOwner) {
+ super.onDestroy(owner)
+ unbindService(connection)
}
//计算状态栏高度
- public int statusBarHeight() {
- int height = 0;
- int resourceId = getResources().getIdentifier(
- "status_bar_height",
- "dimen",
- "android"
- );
+ fun statusBarHeight(): Int {
+ var height = 0
+ val resourceId = resources.getIdentifier(
+ "status_bar_height",
+ "dimen",
+ "android"
+ )
if (resourceId > 0) {
- height = getResources().getDimensionPixelSize(resourceId);
+ height = resources.getDimensionPixelSize(resourceId)
}
- return height;
+ return height
}
-}
+
+ companion object {
+ var context: Context? = null
+ private set
+ var downloadBinder: DownloadBinder? = null
+ private set
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/lsp/view/activity/favtag/FavTagActivity.kt b/app/src/main/java/com/lsp/view/activity/favtag/FavTagActivity.kt
index 0263785..fb6f5cd 100644
--- a/app/src/main/java/com/lsp/view/activity/favtag/FavTagActivity.kt
+++ b/app/src/main/java/com/lsp/view/activity/favtag/FavTagActivity.kt
@@ -11,7 +11,7 @@ import com.google.android.flexbox.*
import com.google.android.material.appbar.AppBarLayout
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
-import com.lsp.view.MyApplication
+import com.lsp.view.YandViewApplication
import com.lsp.view.R
import com.lsp.view.activity.BaseActivity
import com.lsp.view.activity.main.MainActivity
@@ -28,7 +28,7 @@ class FavTagActivity : BaseActivity() {
setSupportActionBar(toolbar)
val appbar = findViewById(R.id.appbar)
val nowHeight = appbar.layoutParams.height
- appbar.layoutParams.height = (application as MyApplication).statusBarHeight()+nowHeight
+ appbar.layoutParams.height = (application as YandViewApplication).statusBarHeight()+nowHeight
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeButtonEnabled(true)
diff --git a/app/src/main/java/com/lsp/view/activity/main/MainActivity.kt b/app/src/main/java/com/lsp/view/activity/main/MainActivity.kt
index 6cda1f2..fb8ebfd 100644
--- a/app/src/main/java/com/lsp/view/activity/main/MainActivity.kt
+++ b/app/src/main/java/com/lsp/view/activity/main/MainActivity.kt
@@ -21,7 +21,7 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.navigation.NavigationView
import com.google.android.material.snackbar.Snackbar
-import com.lsp.view.MyApplication
+import com.lsp.view.YandViewApplication
import com.lsp.view.R
import com.lsp.view.activity.BaseActivity
import com.lsp.view.activity.favtag.FavTagActivity
@@ -60,7 +60,7 @@ class MainActivity : BaseActivity() {
setSupportActionBar(toolbar)
val appbar = findViewById(R.id.appbar)
val nowHeight = appbar.layoutParams.height
- appbar.layoutParams.height = (application as MyApplication).statusBarHeight()+nowHeight
+ appbar.layoutParams.height = (application as YandViewApplication).statusBarHeight()+nowHeight
//到达底部,加载更多数据
adapter.setLoadMoreListener(object : PostAdapter.OnLoadMoreListener {
diff --git a/app/src/main/java/com/lsp/view/activity/setting/SettingsActivity.kt b/app/src/main/java/com/lsp/view/activity/setting/SettingsActivity.kt
index e77e52f..78b75b8 100644
--- a/app/src/main/java/com/lsp/view/activity/setting/SettingsActivity.kt
+++ b/app/src/main/java/com/lsp/view/activity/setting/SettingsActivity.kt
@@ -5,7 +5,7 @@ import android.view.MenuItem
import androidx.appcompat.widget.Toolbar
import androidx.preference.PreferenceFragmentCompat
import com.google.android.material.appbar.AppBarLayout
-import com.lsp.view.MyApplication
+import com.lsp.view.YandViewApplication
import com.lsp.view.R
import com.lsp.view.activity.BaseActivity
@@ -20,7 +20,7 @@ class SettingsActivity : BaseActivity() {
val appbar = findViewById(R.id.appbar)
val nowHeight = appbar.layoutParams.height
- appbar.layoutParams.height = (application as MyApplication).statusBarHeight()+nowHeight
+ appbar.layoutParams.height = (application as YandViewApplication).statusBarHeight()+nowHeight
if (savedInstanceState == null) {
supportFragmentManager
diff --git a/app/src/main/java/com/lsp/view/util/Util.kt b/app/src/main/java/com/lsp/view/util/Util.kt
index 13dfc3d..edb675c 100644
--- a/app/src/main/java/com/lsp/view/util/Util.kt
+++ b/app/src/main/java/com/lsp/view/util/Util.kt
@@ -11,7 +11,7 @@ import android.os.Message
import android.widget.Toast
import androidx.core.content.FileProvider
import com.bumptech.glide.Glide
-import com.lsp.view.MyApplication
+import com.lsp.view.YandViewApplication
import java.io.File
import kotlin.concurrent.thread
@@ -65,11 +65,11 @@ object Util {
}
fun download(file_url: String?, file_ext: String?,md5: String?){
- Toast.makeText(MyApplication.getContext(), "开始保存", Toast.LENGTH_SHORT).show()
+ Toast.makeText(YandViewApplication.context, "开始保存", Toast.LENGTH_SHORT).show()
if (file_url != null) {
if (file_ext != null) {
- MyApplication.getDownloadBinder().downloadPic(file_url, file_ext,handler,md5)
+ YandViewApplication.downloadBinder?.downloadPic(file_url, file_ext,handler,md5)
}
}
}
@@ -79,19 +79,19 @@ object Util {
super.handleMessage(msg)
when(msg.what){
CallBackStatus.OK.ordinal ->{
- Toast.makeText(MyApplication.getContext(), "保存成功", Toast.LENGTH_SHORT).show()
+ Toast.makeText(YandViewApplication.context, "保存成功", Toast.LENGTH_SHORT).show()
}
CallBackStatus.DOWNLOADERROR.ordinal -> {
- Toast.makeText(MyApplication.getContext(), "下载异常", Toast.LENGTH_SHORT).show()
+ Toast.makeText(YandViewApplication.context, "下载异常", Toast.LENGTH_SHORT).show()
}
CallBackStatus.MD5COMPAREERROR.ordinal -> {
- Toast.makeText(MyApplication.getContext(), "文件下载异常,MD5对比失败", Toast.LENGTH_SHORT).show()
+ Toast.makeText(YandViewApplication.context, "文件下载异常,MD5对比失败", Toast.LENGTH_SHORT).show()
}
CallBackStatus.FILEEXISTS.ordinal -> {
- Toast.makeText(MyApplication.getContext(), "文件已经存在", Toast.LENGTH_SHORT).show()
+ Toast.makeText(YandViewApplication.context, "文件已经存在", Toast.LENGTH_SHORT).show()
}
}