convert simpleactivity to kotlin

This commit is contained in:
tibbi 2016-11-06 19:44:26 +01:00
parent dd983c9753
commit fb59224405
5 changed files with 42 additions and 45 deletions

View file

@ -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();
}

View file

@ -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()]);

View file

@ -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);
}
}
}

View file

@ -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) {

View file

@ -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)
}
}
}