Skip to content

Commit dbe7152

Browse files
committed
Refactoring. Migrate java to kotlin
1 parent 25daf61 commit dbe7152

File tree

105 files changed

+586
-2213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+586
-2213
lines changed

app/src/main/java/com/mcal/mcpelauncher/activities/BaseActivity.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,66 +55,64 @@ protected void onCreate(Bundle savedInstanceState) {
5555
}
5656

5757
protected void setDefaultActionBar() {
58-
ActionBar actionBar = getSupportActionBar();
58+
final ActionBar actionBar = getSupportActionBar();
5959
if (actionBar != null) {
60-
@SuppressLint("InflateParams") RelativeLayout actionBarCustomView = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.mcd_actionbar, null);
61-
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
60+
final @SuppressLint("InflateParams") RelativeLayout actionBarCustomView = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.mcd_actionbar, null);
61+
final ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
6262
layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
6363
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
6464
actionBar.setDisplayShowHomeEnabled(false);
6565
actionBar.setDisplayShowCustomEnabled(true);
6666
actionBar.setDisplayShowTitleEnabled(false);
6767
actionBar.setCustomView(actionBarCustomView, layoutParams);
68-
Toolbar parent = (Toolbar) actionBarCustomView.getParent();
68+
final Toolbar parent = (Toolbar) actionBarCustomView.getParent();
6969
parent.setContentInsetsAbsolute(0, 0);
7070

71-
AppCompatTextView titleTV = actionBarCustomView.findViewById(R.id.mcd_actionbar_title);
71+
final AppCompatTextView titleTV = actionBarCustomView.findViewById(R.id.mcd_actionbar_title);
7272
titleTV.setText(getTitle());
7373
}
7474
}
7575

7676
@Override
7777
public void setTitle(int titleId) {
7878
super.setTitle(titleId);
79-
8079
if (getSupportActionBar() != null) {
81-
View actionBarCustomView = getSupportActionBar().getCustomView();
82-
AppCompatTextView titleTV = actionBarCustomView.findViewById(R.id.mcd_actionbar_title);
80+
final View actionBarCustomView = getSupportActionBar().getCustomView();
81+
final AppCompatTextView titleTV = actionBarCustomView.findViewById(R.id.mcd_actionbar_title);
8382
titleTV.setText(titleId);
8483
}
8584
}
8685

8786
@Override
8887
public void setTitle(CharSequence title) {
8988
super.setTitle(title);
90-
9189
if (getSupportActionBar() != null) {
92-
View actionBarCustomView = getSupportActionBar().getCustomView();
93-
AppCompatTextView titleTV = actionBarCustomView.findViewById(R.id.mcd_actionbar_title);
90+
final View actionBarCustomView = getSupportActionBar().getCustomView();
91+
final AppCompatTextView titleTV = actionBarCustomView.findViewById(R.id.mcd_actionbar_title);
9492
titleTV.setText(title);
9593
}
9694
}
9795

9896
protected void setActionBarViewRight(View view) {
9997
if (getSupportActionBar() != null) {
100-
View actionBarCustomView = getSupportActionBar().getCustomView();
101-
RelativeLayout layout = actionBarCustomView.findViewById(R.id.mcd_actionbar_ViewRight);
98+
final View actionBarCustomView = getSupportActionBar().getCustomView();
99+
final RelativeLayout layout = actionBarCustomView.findViewById(R.id.mcd_actionbar_ViewRight);
102100
layout.removeAllViews();
103101
layout.addView(view);
104102
}
105103
}
106104

107105
protected void setActionBarViewLeft(View view) {
108106
if (getSupportActionBar() != null) {
109-
View actionBarCustomView = getSupportActionBar().getCustomView();
110-
RelativeLayout layout = actionBarCustomView.findViewById(R.id.mcd_actionbar_ViewLeft);
107+
final View actionBarCustomView = getSupportActionBar().getCustomView();
108+
final RelativeLayout layout = actionBarCustomView.findViewById(R.id.mcd_actionbar_ViewLeft);
111109
layout.removeAllViews();
112110
layout.addView(view);
113111
}
114112
}
115113

116114
protected void setActionBarButtonCloseRight() {
117-
View buttonClose = getLayoutInflater().inflate(R.layout.moddedpe_ui_button_close, null);
115+
final View buttonClose = getLayoutInflater().inflate(R.layout.moddedpe_ui_button_close, null);
118116
buttonClose.findViewById(R.id.moddedpe_ui_button_item_image_button).setOnClickListener(p1 -> finish());
119117
setActionBarViewRight(buttonClose);
120118
}
@@ -123,7 +121,6 @@ protected void setActionBarButtonCloseRight() {
123121
@Override
124122
public void onWindowFocusChanged(boolean hasFocus) {
125123
super.onWindowFocusChanged(hasFocus);
126-
127124
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mcd_bg);
128125
bitmap = BitmapRepeater.repeat(getWindowManager().getDefaultDisplay().getWidth(), getWindowManager().getDefaultDisplay().getHeight(), bitmap);
129126
getWindow().getDecorView().setBackground(new BitmapDrawable(bitmap));

app/src/main/java/com/mcal/mcpelauncher/activities/SplashesActivity.java

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (C) 2018-2021 Тимашков Иван
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.mcal.mcpelauncher.activities
18+
19+
import android.annotation.SuppressLint
20+
import android.content.Intent
21+
import android.os.Build
22+
import android.os.Bundle
23+
import android.view.View
24+
import com.mcal.mcpelauncher.R
25+
import com.mcal.mcpelauncher.utils.DataPreloader
26+
import com.mcal.mcpelauncher.utils.PreloadingFinishedListener
27+
28+
/**
29+
* @author Тимашков Иван
30+
* @author https://github.com/TimScriptov
31+
*/
32+
class SplashesActivity : BaseActivity(), PreloadingFinishedListener {
33+
override fun onCreate(savedInstanceState: Bundle?) {
34+
super.onCreate(savedInstanceState)
35+
setContentView(R.layout.moddedpe_splashes)
36+
initInstance()
37+
}
38+
39+
@SuppressLint("ObsoleteSdkInt")
40+
override fun onWindowFocusChanged(hasFocus: Boolean) {
41+
super.onWindowFocusChanged(hasFocus)
42+
if (hasFocus && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
43+
val decorView = window.decorView
44+
@Suppress("DEPRECATION")
45+
decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
46+
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
47+
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
48+
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
49+
or View.SYSTEM_UI_FLAG_FULLSCREEN
50+
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
51+
}
52+
}
53+
54+
private fun initInstance() {
55+
DataPreloader(this).preload(applicationContext)
56+
}
57+
58+
override fun onPreloadingFinished() {
59+
val intent = Intent(this@SplashesActivity, MainActivity::class.java)
60+
startActivity(intent)
61+
finish()
62+
}
63+
}

app/src/main/java/com/mcal/mcpelauncher/fragments/MainSettingsFragment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import androidx.preference.ListPreference;
3232
import androidx.preference.Preference;
3333
import androidx.preference.PreferenceFragmentCompat;
34+
import androidx.preference.SwitchPreference;
3435

3536
import com.google.android.material.snackbar.Snackbar;
3637
import com.mcal.mcpelauncher.R;
@@ -41,7 +42,6 @@
4142
import com.mcal.mcpelauncher.ui.AboutActivity;
4243
import com.mcal.mcpelauncher.ui.DirPickerActivity;
4344
import com.mcal.mcpelauncher.utils.I18n;
44-
import com.mcal.mcpelauncher.view.SwitchPreference;
4545

4646
import org.jetbrains.annotations.NotNull;
4747

@@ -81,7 +81,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
8181
});
8282

8383
SwitchPreference mSafeModePreference = findPreference("safe_mode");
84-
mSafeModePreference.setWidgetLayoutResource(R.layout.switch_preference);
8584
mSafeModePreference.setOnPreferenceChangeListener((p1, p2) -> {
8685
Preferences.setSafeMode((boolean) p2);
8786
return true;

app/src/main/java/com/mcal/mcpelauncher/utils/DataPreloader.java

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2018-2021 Тимашков Иван
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.mcal.mcpelauncher.utils
18+
19+
import android.content.Context
20+
import com.mcal.mcpelauncher.ModdedPEApplication
21+
import com.mcal.pesdk.PESdk
22+
import kotlinx.coroutines.CoroutineScope
23+
import kotlinx.coroutines.Dispatchers
24+
import kotlinx.coroutines.delay
25+
import kotlinx.coroutines.launch
26+
27+
/**
28+
* @author Тимашков Иван
29+
* @author https://github.com/TimScriptov
30+
*/
31+
class DataPreloader(private val mListener: PreloadingFinishedListener) {
32+
private var mIsSleepingFinished = false
33+
private var mIsPreloadingFinished = false
34+
fun preload(context_a: Context) {
35+
CoroutineScope(Dispatchers.IO).launch {
36+
ModdedPEApplication.mPESdk = PESdk(context_a)
37+
ModdedPEApplication.mPESdk.init()
38+
mIsPreloadingFinished = true
39+
checkFinish()
40+
}
41+
CoroutineScope(Dispatchers.IO).launch {
42+
try {
43+
delay(5000L)
44+
} catch (e: InterruptedException) {
45+
e.printStackTrace()
46+
}
47+
mIsSleepingFinished = true
48+
checkFinish()
49+
}
50+
}
51+
52+
private fun checkFinish() {
53+
if (mIsPreloadingFinished && mIsSleepingFinished) {
54+
mListener.onPreloadingFinished()
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)