From fb59224405965ff32b357dd7494fc4d93e33cc16 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 6 Nov 2016 19:44:26 +0100 Subject: [PATCH] convert simpleactivity to kotlin --- .../gallery/activities/MainActivity.java | 6 ++-- .../gallery/activities/MediaActivity.java | 10 +++--- .../gallery/activities/SimpleActivity.java | 35 ------------------- .../gallery/activities/ViewPagerActivity.java | 4 +-- .../gallery/activities/SimpleActivity.kt | 32 +++++++++++++++++ 5 files changed, 42 insertions(+), 45 deletions(-) delete mode 100644 app/src/main/java/com/simplemobiletools/gallery/activities/SimpleActivity.java create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index 253aa3447..5855f9afa 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -472,7 +472,7 @@ public class MainActivity extends SimpleActivity for (int i = 0; i < cnt; i++) { if (items.valueAt(i)) { final int id = items.keyAt(i); - if (mConfig.getIsFolderHidden(mDirs.get(id).getPath())) + if (getConfig().getIsFolderHidden(mDirs.get(id).getPath())) hiddenCnt++; else unhiddenCnt++; @@ -526,12 +526,12 @@ public class MainActivity extends SimpleActivity } private void hideFolders() { - mConfig.addHiddenDirectories(getSelectedPaths()); + getConfig().addHiddenDirectories(getSelectedPaths()); getDirectories(); } private void unhideFolders() { - mConfig.removeHiddenDirectories(getSelectedPaths()); + getConfig().removeHiddenDirectories(getSelectedPaths()); getDirectories(); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index f9e5ffcb8..ad93bac40 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -132,7 +132,7 @@ public class MediaActivity extends SimpleActivity public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_media, menu); - final boolean isFolderHidden = mConfig.getIsFolderHidden(mPath); + final boolean isFolderHidden = getConfig().getIsFolderHidden(mPath); menu.findItem(R.id.hide_folder).setVisible(!isFolderHidden); menu.findItem(R.id.unhide_folder).setVisible(isFolderHidden); @@ -174,16 +174,16 @@ public class MediaActivity extends SimpleActivity } private void hideDirectory() { - mConfig.addHiddenDirectory(mPath); + getConfig().addHiddenDirectory(mPath); - if (!mConfig.getShowHiddenFolders()) + if (!getConfig().getShowHiddenFolders()) finish(); else invalidateOptionsMenu(); } private void unhideDirectory() { - mConfig.removeHiddenDirectory(mPath); + getConfig().removeHiddenDirectory(mPath); invalidateOptionsMenu(); } @@ -236,7 +236,7 @@ public class MediaActivity extends SimpleActivity } } - Medium.mSorting = mConfig.getSorting(); + Medium.mSorting = getConfig().getSorting(); Collections.sort(media); final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/SimpleActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/SimpleActivity.java deleted file mode 100644 index 616aa4aec..000000000 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/SimpleActivity.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.simplemobiletools.gallery.activities; - -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.view.MenuItem; - -import com.simplemobiletools.gallery.Config; -import com.simplemobiletools.gallery.R; - -public class SimpleActivity extends AppCompatActivity { - protected Config mConfig; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - mConfig = Config.newInstance(getApplicationContext()); - int theme = mConfig.getIsDarkTheme() ? R.style.AppTheme_Dark : R.style.AppTheme; - if (this instanceof ViewPagerActivity || this instanceof PhotoActivity || this instanceof VideoActivity) { - theme = mConfig.getIsDarkTheme() ? R.style.FullScreenTheme_Dark : R.style.FullScreenTheme; - } - setTheme(theme); - super.onCreate(savedInstanceState); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } -} diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index 5a4b7a6d9..057c2a9c3 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -247,7 +247,7 @@ public class ViewPagerActivity extends SimpleActivity @TargetApi(Build.VERSION_CODES.KITKAT) private void saveTreeUri(Intent resultData) { Uri treeUri = resultData.getData(); - mConfig.setTreeUri(resultData.getData().toString()); + getConfig().setTreeUri(resultData.getData().toString()); int takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION; getContentResolver().takePersistableUriPermission(treeUri, takeFlags); @@ -393,7 +393,7 @@ public class ViewPagerActivity extends SimpleActivity } } - Medium.mSorting = mConfig.getSorting(); + Medium.mSorting = getConfig().getSorting(); Collections.sort(media); int j = 0; for (Medium medium : media) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt new file mode 100644 index 000000000..3d3251653 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt @@ -0,0 +1,32 @@ +package com.simplemobiletools.gallery.activities + +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.view.MenuItem + +import com.simplemobiletools.gallery.Config +import com.simplemobiletools.gallery.R + +open class SimpleActivity : AppCompatActivity() { + lateinit var config: Config + + override fun onCreate(savedInstanceState: Bundle?) { + config = Config.newInstance(applicationContext) + var theme = if (config.isDarkTheme) R.style.AppTheme_Dark else R.style.AppTheme + if (this is ViewPagerActivity || this is PhotoActivity || this is VideoActivity) { + theme = if (config.isDarkTheme) R.style.FullScreenTheme_Dark else R.style.FullScreenTheme + } + setTheme(theme) + super.onCreate(savedInstanceState) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + android.R.id.home -> { + finish() + true + } + else -> super.onOptionsItemSelected(item) + } + } +}