Add set location summary update
This commit is contained in:
1 parent
dd52e06488
commit
903d25aee2
4 files changed
+64
-26
No files matched your search
@@ -25,6 +25,8 @@ public final class Constants {
|
||||
public static final int MESSENGER_ID_SIGN_IN_OR_OUT;
|
||||
public static final int MESSENGER_ID_USER_AVATAR;
|
||||
public static final int MESSENGER_ID_JPN_TITLE;
|
||||
public static final int MESSENGER_ID_IMAGE_DOWNLOAD_LOCATION;
|
||||
public static final int MESSENGER_ID_ARCHIVE_DOWNLOAD_LOCATION;
|
||||
|
||||
static {
|
||||
Messenger messenger = Messenger.getInstance();
|
||||
@@ -33,5 +35,7 @@ public final class Constants {
|
||||
MESSENGER_ID_SIGN_IN_OR_OUT = messenger.newId();
|
||||
MESSENGER_ID_USER_AVATAR = messenger.newId();
|
||||
MESSENGER_ID_JPN_TITLE = messenger.newId();
|
||||
MESSENGER_ID_IMAGE_DOWNLOAD_LOCATION = messenger.newId();
|
||||
MESSENGER_ID_ARCHIVE_DOWNLOAD_LOCATION = messenger.newId();
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.util.Settings;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
@@ -34,6 +35,7 @@ import com.hippo.scene.Scene;
|
||||
import com.hippo.scene.SimpleDialog;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.widget.DirExplorer;
|
||||
import com.hippo.yorozuya.Messenger;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -125,8 +127,10 @@ public class DirPickScene extends AppbarScene implements View.OnClickListener,
|
||||
private void save(UniFile uniFile) {
|
||||
if (ACTION_IMAGE_DOWNLOAD_LOCATION.equals(mAction)) {
|
||||
Settings.putImageDownloadLocation(uniFile);
|
||||
Messenger.getInstance().notify(Constants.MESSENGER_ID_IMAGE_DOWNLOAD_LOCATION, uniFile);
|
||||
} else if (ACTION_ARCHIVE_DOWNLOAD_LOCATION.equals(mAction)) {
|
||||
Settings.putArchiveDownloadLocation(uniFile);
|
||||
Messenger.getInstance().notify(Constants.MESSENGER_ID_ARCHIVE_DOWNLOAD_LOCATION, uniFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+54
-26
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.ui.scene.preference;
|
||||
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.util.Settings;
|
||||
import com.hippo.scene.Announcer;
|
||||
@@ -25,12 +26,17 @@ import com.hippo.scene.preference.Preference;
|
||||
import com.hippo.scene.preference.PreferenceScene;
|
||||
import com.hippo.scene.preference.PreferenceSet;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.Messenger;
|
||||
|
||||
public class DownloadSettingsScene extends PreferenceScene implements Preference.OnClickListener {
|
||||
public class DownloadSettingsScene extends PreferenceScene implements Preference.OnClickListener,
|
||||
Messenger.Receiver {
|
||||
|
||||
private static final String KEY_IMAGE_DOWNLOAD_LOACTION = "image_download_location";
|
||||
private static final String KEY_ARCHIVE_DOWNLOAD_LOACTION = "archive_download_location";
|
||||
|
||||
private static Preference mImagePreference;
|
||||
private static Preference mArchivePreference;
|
||||
|
||||
@Override
|
||||
protected void onCreate(boolean rebirth) {
|
||||
super.onCreate(rebirth);
|
||||
@@ -41,46 +47,54 @@ public class DownloadSettingsScene extends PreferenceScene implements Preference
|
||||
setPreferenceSet(getPreferenceSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInit() {
|
||||
super.onInit();
|
||||
|
||||
Messenger.getInstance().register(Constants.MESSENGER_ID_IMAGE_DOWNLOAD_LOCATION, this);
|
||||
Messenger.getInstance().register(Constants.MESSENGER_ID_ARCHIVE_DOWNLOAD_LOCATION, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDie() {
|
||||
super.onDie();
|
||||
|
||||
Messenger.getInstance().unregister(Constants.MESSENGER_ID_IMAGE_DOWNLOAD_LOCATION, this);
|
||||
Messenger.getInstance().unregister(Constants.MESSENGER_ID_ARCHIVE_DOWNLOAD_LOCATION, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIconClick() {
|
||||
finish();
|
||||
}
|
||||
|
||||
private String getPath(UniFile file) {
|
||||
if (file != null) {
|
||||
return file.getUri().getPath();
|
||||
} else {
|
||||
return getStageActivity().getResources().getString(R.string.unknown);
|
||||
}
|
||||
}
|
||||
|
||||
private PreferenceSet[] getPreferenceSet() {
|
||||
Resources resources = getStageActivity().getResources();
|
||||
|
||||
String imageSummary;
|
||||
UniFile imageDir = Settings.getImageDownloadLocation();
|
||||
if (imageDir == null) {
|
||||
imageSummary = resources.getString(R.string.unknown);
|
||||
} else {
|
||||
imageSummary = imageDir.getUri().getPath();
|
||||
}
|
||||
|
||||
Preference imagePreference = new Preference(
|
||||
mImagePreference = new Preference(
|
||||
KEY_IMAGE_DOWNLOAD_LOACTION,
|
||||
resources.getString(R.string.settings_image_download_location),
|
||||
imageSummary);
|
||||
imagePreference.setOnClickListener(this);
|
||||
getPath(Settings.getImageDownloadLocation()));
|
||||
mImagePreference.setOnClickListener(this);
|
||||
|
||||
String archiveSummary;
|
||||
UniFile archiveDir = Settings.getArchiveDownloadLocation();
|
||||
if (archiveDir == null) {
|
||||
archiveSummary = resources.getString(R.string.unknown);
|
||||
} else {
|
||||
archiveSummary = archiveDir.getUri().getPath();
|
||||
}
|
||||
|
||||
Preference archivePreference = new Preference(
|
||||
mArchivePreference = new Preference(
|
||||
KEY_ARCHIVE_DOWNLOAD_LOACTION,
|
||||
resources.getString(R.string.settings_archive_download_location),
|
||||
archiveSummary);
|
||||
archivePreference.setOnClickListener(this);
|
||||
getPath(Settings.getArchiveDownloadLocation()));
|
||||
mArchivePreference.setOnClickListener(this);
|
||||
|
||||
PreferenceSet preferenceSet = new PreferenceSet();
|
||||
preferenceSet.setPreferenceList(new Preference[] {
|
||||
imagePreference,
|
||||
archivePreference
|
||||
mImagePreference,
|
||||
mArchivePreference
|
||||
});
|
||||
|
||||
return new PreferenceSet[] {
|
||||
@@ -91,14 +105,28 @@ public class DownloadSettingsScene extends PreferenceScene implements Preference
|
||||
@Override
|
||||
public boolean onClick(Preference preference) {
|
||||
String key = preference.getKey();
|
||||
Announcer announcer;
|
||||
switch (key) {
|
||||
case KEY_IMAGE_DOWNLOAD_LOACTION:
|
||||
Announcer announcer = new Announcer();
|
||||
announcer = new Announcer();
|
||||
announcer.setAction(DirPickScene.ACTION_IMAGE_DOWNLOAD_LOCATION);
|
||||
startScene(DirPickScene.class, announcer);
|
||||
return true;
|
||||
case KEY_ARCHIVE_DOWNLOAD_LOACTION:
|
||||
announcer = new Announcer();
|
||||
announcer.setAction(DirPickScene.ACTION_ARCHIVE_DOWNLOAD_LOCATION);
|
||||
startScene(DirPickScene.class, announcer);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(int id, Object obj) {
|
||||
if (id == Constants.MESSENGER_ID_IMAGE_DOWNLOAD_LOCATION) {
|
||||
mImagePreference.setSummary(getPath((UniFile) obj));
|
||||
} else if (id == Constants.MESSENGER_ID_ARCHIVE_DOWNLOAD_LOCATION) {
|
||||
mArchivePreference.setSummary(getPath((UniFile) obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.widget.recyclerview.EasyRecyclerView;
|
||||
import com.hippo.widget.recyclerview.LinearDividerItemDecoration;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
@@ -76,6 +77,7 @@ public class DirExplorer extends EasyRecyclerView implements EasyRecyclerView.On
|
||||
decoration.setShowLastDivider(true);
|
||||
decoration.setPadding(context.getResources().getDimensionPixelOffset(R.dimen.keyline_margin));
|
||||
addItemDecoration(decoration);
|
||||
setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
setOnItemClickListener(this);
|
||||
|
||||
mCurrentFile = Environment.getExternalStorageDirectory();
|
||||
|
||||
Reference in new issue
Block a user