diff options
Diffstat (limited to 'org.fox.ttrss/src/main/java/org')
4 files changed, 54 insertions, 11 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/Application.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/Application.java index dd134e8c..a9a54fb4 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/Application.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/Application.java @@ -1,6 +1,7 @@ package org.fox.ttrss; import android.os.Bundle; +import android.util.ArraySet; import com.livefront.bridge.Bridge; import com.livefront.bridge.SavedStateHandler; @@ -10,6 +11,9 @@ import org.fox.ttrss.types.ArticleList; import androidx.annotation.NonNull; import androidx.annotation.Nullable; + +import java.util.HashMap; + import icepick.Icepick; public class Application extends android.app.Application { @@ -21,6 +25,8 @@ public class Application extends android.app.Application { public int m_selectedArticleId; public String m_sessionId; public int m_apiLevel; + public HashMap<String, String> m_customSortTypes = new HashMap<>(); + public static Application getInstance(){ return m_singleton; } @@ -50,6 +56,7 @@ public class Application extends android.app.Application { out.putString("gs:sessionId", m_sessionId); out.putInt("gs:apiLevel", m_apiLevel); out.putInt("gs:selectedArticleId", m_selectedArticleId); + out.putSerializable("gs:customSortTypes", m_customSortTypes); } public void load(Bundle in) { @@ -57,6 +64,7 @@ public class Application extends android.app.Application { m_sessionId = in.getString("gs:sessionId"); m_apiLevel = in.getInt("gs:apiLevel"); m_selectedArticleId = in.getInt("gs:selectedArticleId"); + m_customSortTypes = (HashMap<String, String>) in.getSerializable("gs:customSortTypes"); } } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/MasterActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/MasterActivity.java index 121b836c..12c2d5ad 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/MasterActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/MasterActivity.java @@ -26,6 +26,8 @@ import org.fox.ttrss.types.FeedCategory; import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.stream.Stream; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.widget.Toolbar; @@ -369,29 +371,37 @@ public class MasterActivity extends OnlineActivity implements HeadlinesEventList String sortMode = getSortMode(); - int selectedIndex = 0; + LinkedHashMap<String, String> sortTypes = new LinkedHashMap<String, String>(); + + sortTypes.put("", getString(R.string.headlines_sort_default)); + sortTypes.put("feed_dates", getString(R.string.headlines_sort_newest_first)); + sortTypes.put("date_reverse", getString(R.string.headlines_sort_oldest_first)); + sortTypes.put("title", getString(R.string.headlines_sort_title)); + + sortTypes.putAll(Application.getInstance().m_customSortTypes); - if (sortMode.equals("feed_dates")) { + + /*if (sortMode.equals("feed_dates")) { selectedIndex = 1; } else if (sortMode.equals("date_reverse")) { selectedIndex = 2; } else if (sortMode.equals("title")) { selectedIndex = 3; - } + }*/ + + int selectedIndex = 0; AlertDialog.Builder builder = new AlertDialog.Builder(this) .setTitle(getString(R.string.headlines_sort_articles_title)) .setSingleChoiceItems( - new String[] { - getString(R.string.headlines_sort_default), - getString(R.string.headlines_sort_newest_first), - getString(R.string.headlines_sort_oldest_first), - getString(R.string.headlines_sort_title) - }, + (CharSequence[])sortTypes.keySet().toArray(), selectedIndex, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { + + Log.d(TAG, "sort selected index:" + which); + switch (which) { case 0: setSortMode("default"); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java index 33e3b5a7..64e1dfed 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java @@ -1,5 +1,6 @@ package org.fox.ttrss; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; @@ -34,6 +35,7 @@ import android.widget.TextView; import com.github.javiersantos.appupdater.AppUpdater; import com.github.javiersantos.appupdater.enums.UpdateFrom; import com.google.gson.Gson; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; @@ -51,6 +53,7 @@ import org.fox.ttrss.util.ImageCacheService; import java.lang.reflect.Type; import java.util.HashMap; import java.util.List; +import java.util.Map; import androidx.appcompat.view.ActionMode; import androidx.appcompat.widget.Toolbar; @@ -1192,7 +1195,12 @@ public class OnlineActivity extends CommonActivity { public int getApiLevel() { return Application.getInstance().m_apiLevel; } - + + private void setCustomSortTypes(Map<String, String> customSortTypes) { + Application.getInstance().m_customSortTypes.clear(); + Application.getInstance().m_customSortTypes.putAll(customSortTypes); + } + protected void setApiLevel(int apiLevel) { Application.getInstance().m_apiLevel = apiLevel; } @@ -1575,6 +1583,7 @@ public class OnlineActivity extends CommonActivity { } @SuppressWarnings("unchecked") + @SuppressLint("StaticFieldLeak") protected void onPostExecute(JsonElement result) { if (result != null) { try { @@ -1590,6 +1599,20 @@ public class OnlineActivity extends CommonActivity { if (apiLevel != null) { setApiLevel(apiLevel.getAsInt()); Log.d(TAG, "Received API level: " + getApiLevel()); + + // get custom sort from configuration object + if (getApiLevel() >= 17) { + + // daemon_is_running, icons_dir, etc... + JsonObject config = content.get("config").getAsJsonObject(); + + Type hashType = new TypeToken<Map<String, String>>(){}.getType(); + Map<String, String> customSortTypes = new Gson().fromJson(config.get("custom_sort_types"), hashType); + + setCustomSortTypes(customSortTypes); + + Log.d(TAG, "test"); + } if (m_listener != null) { m_listener.OnLoginSuccess(); @@ -1671,7 +1694,7 @@ public class OnlineActivity extends CommonActivity { } - public String getSortMode() { + public String getSortMode() { return m_prefs.getString("headlines_sort_mode", "default"); } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineMasterActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineMasterActivity.java index cdaa794e..0a3b6378 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineMasterActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineMasterActivity.java @@ -25,6 +25,8 @@ import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; +import java.util.HashMap; + public class OfflineMasterActivity extends OfflineActivity implements OfflineHeadlinesEventListener { private final String TAG = this.getClass().getSimpleName(); |