From 2067c8eed1b60db536c5c93618167af9409bc315 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Wed, 1 Mar 2023 18:20:23 -0500 Subject: [PATCH] Android: Convert ConvertActivity to Kotlin --- .../activities/ConvertActivity.java | 90 ------------------- .../dolphinemu/activities/ConvertActivity.kt | 84 +++++++++++++++++ 2 files changed, 84 insertions(+), 90 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java deleted file mode 100644 index 9525b5cf39..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.activities; - -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; - -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowCompat; -import androidx.core.view.WindowInsetsCompat; - -import com.google.android.material.color.MaterialColors; - -import org.dolphinemu.dolphinemu.R; -import org.dolphinemu.dolphinemu.databinding.ActivityConvertBinding; -import org.dolphinemu.dolphinemu.fragments.ConvertFragment; -import org.dolphinemu.dolphinemu.utils.InsetsHelper; -import org.dolphinemu.dolphinemu.utils.ThemeHelper; - -public class ConvertActivity extends AppCompatActivity -{ - private static final String ARG_GAME_PATH = "game_path"; - - private ActivityConvertBinding mBinding; - - public static void launch(Context context, String gamePath) - { - Intent launcher = new Intent(context, ConvertActivity.class); - launcher.putExtra(ARG_GAME_PATH, gamePath); - context.startActivity(launcher); - } - - @Override - protected void onCreate(Bundle savedInstanceState) - { - ThemeHelper.setTheme(this); - - super.onCreate(savedInstanceState); - - mBinding = ActivityConvertBinding.inflate(getLayoutInflater()); - setContentView(mBinding.getRoot()); - - WindowCompat.setDecorFitsSystemWindows(getWindow(), false); - - String path = getIntent().getStringExtra(ARG_GAME_PATH); - - ConvertFragment fragment = (ConvertFragment) getSupportFragmentManager() - .findFragmentById(R.id.fragment_convert); - if (fragment == null) - { - fragment = ConvertFragment.newInstance(path); - getSupportFragmentManager().beginTransaction().add(R.id.fragment_convert, fragment).commit(); - } - - mBinding.toolbarConvertLayout.setTitle(getString(R.string.convert_convert)); - setSupportActionBar(mBinding.toolbarConvert); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - setInsets(); - ThemeHelper.enableScrollTint(this, mBinding.toolbarConvert, mBinding.appbarConvert); - } - - @Override - public boolean onSupportNavigateUp() - { - onBackPressed(); - return true; - } - - private void setInsets() - { - ViewCompat.setOnApplyWindowInsetsListener(mBinding.appbarConvert, (v, windowInsets) -> - { - Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); - - InsetsHelper.insetAppBar(insets, mBinding.appbarConvert); - - mBinding.scrollViewConvert.setPadding(insets.left, 0, insets.right, insets.bottom); - - InsetsHelper.applyNavbarWorkaround(insets.bottom, mBinding.workaroundView); - ThemeHelper.setNavigationBarColor(this, - MaterialColors.getColor(mBinding.appbarConvert, R.attr.colorSurface)); - - return windowInsets; - }); - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.kt new file mode 100644 index 0000000000..2fcc939983 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.kt @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.activities + +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowCompat +import androidx.core.view.WindowInsetsCompat +import com.google.android.material.color.MaterialColors +import org.dolphinemu.dolphinemu.R +import org.dolphinemu.dolphinemu.databinding.ActivityConvertBinding +import org.dolphinemu.dolphinemu.fragments.ConvertFragment +import org.dolphinemu.dolphinemu.fragments.ConvertFragment.Companion.newInstance +import org.dolphinemu.dolphinemu.utils.InsetsHelper +import org.dolphinemu.dolphinemu.utils.ThemeHelper + +class ConvertActivity : AppCompatActivity() { + private lateinit var binding: ActivityConvertBinding + + override fun onCreate(savedInstanceState: Bundle?) { + ThemeHelper.setTheme(this) + + super.onCreate(savedInstanceState) + + binding = ActivityConvertBinding.inflate(layoutInflater) + setContentView(binding.root) + + WindowCompat.setDecorFitsSystemWindows(window, false) + + val path = intent.getStringExtra(ARG_GAME_PATH) + + var fragment = supportFragmentManager + .findFragmentById(R.id.fragment_convert) as ConvertFragment? + if (fragment == null) { + fragment = newInstance(path!!) + supportFragmentManager.beginTransaction().add(R.id.fragment_convert, fragment).commit() + } + + binding.toolbarConvertLayout.title = getString(R.string.convert_convert) + setSupportActionBar(binding.toolbarConvert) + supportActionBar!!.setDisplayHomeAsUpEnabled(true) + + setInsets() + ThemeHelper.enableScrollTint(this, binding.toolbarConvert, binding.appbarConvert) + } + + override fun onSupportNavigateUp(): Boolean { + onBackPressed() + return true + } + + private fun setInsets() { + ViewCompat.setOnApplyWindowInsetsListener(binding.appbarConvert) { _: View?, windowInsets: WindowInsetsCompat -> + val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) + + InsetsHelper.insetAppBar(insets, binding.appbarConvert) + + binding.scrollViewConvert.setPadding(insets.left, 0, insets.right, insets.bottom) + + InsetsHelper.applyNavbarWorkaround(insets.bottom, binding.workaroundView) + ThemeHelper.setNavigationBarColor( + this, + MaterialColors.getColor(binding.appbarConvert, R.attr.colorSurface) + ) + + windowInsets + } + } + + companion object { + private const val ARG_GAME_PATH = "game_path" + + @JvmStatic + fun launch(context: Context, gamePath: String) { + val launcher = Intent(context, ConvertActivity::class.java) + launcher.putExtra(ARG_GAME_PATH, gamePath) + context.startActivity(launcher) + } + } +}