mirror of
https://github.com/gsantner/dandelion
synced 2024-11-25 22:02:08 +01:00
Cache last podlist
This commit is contained in:
parent
d8ca356d6c
commit
85038e90f2
3 changed files with 51 additions and 18 deletions
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package com.github.dfa.diaspora_android.activity;
|
package com.github.dfa.diaspora_android.activity;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -29,7 +28,7 @@ import android.content.IntentFilter;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -79,7 +78,8 @@ public class PodSelectionActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
listPods.setTextFilterEnabled(true);
|
listPods.setTextFilterEnabled(true);
|
||||||
registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE));
|
setListedPods(app.getSettings().getPreviousPodlist());
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE_PODS_RECEIVED));
|
||||||
|
|
||||||
if (!Helpers.isOnline(PodSelectionActivity.this)) {
|
if (!Helpers.isOnline(PodSelectionActivity.this)) {
|
||||||
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||||
|
@ -93,11 +93,12 @@ public class PodSelectionActivity extends AppCompatActivity {
|
||||||
if (intent.hasExtra("pods")) {
|
if (intent.hasExtra("pods")) {
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
String[] pods = extras.getStringArray("pods");
|
String[] pods = extras.getStringArray("pods");
|
||||||
|
if (pods != null && pods.length > 0) {
|
||||||
if (pods != null && pods.length > 0)
|
app.getSettings().setPreviousPodlist(pods);
|
||||||
setListedPods(pods);
|
setListedPods(pods);
|
||||||
else {
|
} else {
|
||||||
Snackbar.make(listPods, R.string.podlist_error, Snackbar.LENGTH_LONG).show();
|
setListedPods(app.getSettings().getPreviousPodlist());
|
||||||
|
Snackbar.make(listPods, R.string.podlist_error, Snackbar.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +123,6 @@ public class PodSelectionActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private void setListedPods(String[] listedPodsArr) {
|
private void setListedPods(String[] listedPodsArr) {
|
||||||
final ArrayList<String> listedPodsList = new ArrayList<>();
|
final ArrayList<String> listedPodsList = new ArrayList<>();
|
||||||
|
|
||||||
for (String pod : listedPodsArr) {
|
for (String pod : listedPodsArr) {
|
||||||
listedPodsList.add(pod.toLowerCase());
|
listedPodsList.add(pod.toLowerCase());
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,13 @@ public class PodSelectionActivity extends AppCompatActivity {
|
||||||
PodSelectionActivity.this,
|
PodSelectionActivity.this,
|
||||||
android.R.layout.simple_list_item_1,
|
android.R.layout.simple_list_item_1,
|
||||||
listedPodsList);
|
listedPodsList);
|
||||||
|
|
||||||
|
// save index and top position
|
||||||
|
int index = listPods.getFirstVisiblePosition();
|
||||||
|
View v = listPods.getChildAt(0);
|
||||||
|
int top = (v == null) ? 0 : (v.getTop() - listPods.getPaddingTop());
|
||||||
listPods.setAdapter(adapter);
|
listPods.setAdapter(adapter);
|
||||||
|
listPods.setSelectionFromTop(index, top);
|
||||||
|
|
||||||
adapter.getFilter().filter(editFilter.getText());
|
adapter.getFilter().filter(editFilter.getText());
|
||||||
editFilter.addTextChangedListener(new TextWatcher() {
|
editFilter.addTextChangedListener(new TextWatcher() {
|
||||||
|
@ -213,7 +219,7 @@ public class PodSelectionActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
unregisterReceiver(podListReceiver);
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(podListReceiver);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,28 @@ public class AppSettings {
|
||||||
pref.edit().putBoolean(key, value).apply();
|
pref.edit().putBoolean(key, value).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setStringArray(SharedPreferences pref, String key, String[] values){
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
for(String value : values){
|
||||||
|
sb.append("%%%");
|
||||||
|
sb.append(value);
|
||||||
|
}
|
||||||
|
setString(pref,key,sb.toString().replaceFirst("%%%",""));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] getStringArray(SharedPreferences pref, String key){
|
||||||
|
String value = pref.getString(key,"%%%");
|
||||||
|
if (value.equals("%%%")){
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
return value.split("%%%");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Preferences
|
// Preferences
|
||||||
*/
|
*/
|
||||||
public static class PREF {
|
public static class PREF {
|
||||||
|
private static final String PREVIOUS_PODLIST = "previousPodlist";
|
||||||
private static final String IS_LOAD_IMAGES = "loadImages";
|
private static final String IS_LOAD_IMAGES = "loadImages";
|
||||||
private static final String MINIMUM_FONT_SIZE = "minimumFontSize";
|
private static final String MINIMUM_FONT_SIZE = "minimumFontSize";
|
||||||
private static final String PODUSERPROFILE_AVATAR_URL = "podUserProfile_avatar";
|
private static final String PODUSERPROFILE_AVATAR_URL = "podUserProfile_avatar";
|
||||||
|
@ -106,4 +124,12 @@ public class AppSettings {
|
||||||
public boolean hasPodDomain(){
|
public boolean hasPodDomain(){
|
||||||
return !prefPod.getString(PREF.PODDOMAIN, "").equals("");
|
return !prefPod.getString(PREF.PODDOMAIN, "").equals("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getPreviousPodlist(){
|
||||||
|
return getStringArray(prefApp, PREF.PREVIOUS_PODLIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviousPodlist(String[] pods){
|
||||||
|
setStringArray(prefApp, PREF.PREVIOUS_PODLIST, pods);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,11 @@ import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.github.dfa.diaspora_android.App;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.StatusLine;
|
import org.apache.http.StatusLine;
|
||||||
|
@ -42,9 +45,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GetPodsService extends Service {
|
public class GetPodsService extends Service {
|
||||||
public static final String MESSAGE = "com.github.dfa.diaspora.podsreceived";
|
public static final String MESSAGE_PODS_RECEIVED = "com.github.dfa.diaspora.podsreceived";
|
||||||
|
private static final String TAG = App.TAG;
|
||||||
private static final String TAG = "Diaspora Pod Service";
|
|
||||||
|
|
||||||
public GetPodsService() {
|
public GetPodsService() {
|
||||||
}
|
}
|
||||||
|
@ -62,7 +64,7 @@ public class GetPodsService extends Service {
|
||||||
* A few modifications and adaptations were made by me.
|
* A few modifications and adaptations were made by me.
|
||||||
* Source:
|
* Source:
|
||||||
* https://github.com/voidcode/Diaspora-Webclient/blob/master/src/com/voidcode/diasporawebclient/getPodlistTask.java
|
* https://github.com/voidcode/Diaspora-Webclient/blob/master/src/com/voidcode/diasporawebclient/getPodlistTask.java
|
||||||
* Thanks to Terkel Sørensen
|
* Thanks to Terkel Sørensen ; License : GPLv3
|
||||||
*/
|
*/
|
||||||
AsyncTask<Void, Void, String[]> getPodsAsync = new AsyncTask<Void, Void, String[]>() {
|
AsyncTask<Void, Void, String[]> getPodsAsync = new AsyncTask<Void, Void, String[]>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,11 +120,10 @@ public class GetPodsService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String[] strings) {
|
protected void onPostExecute(String[] pods) {
|
||||||
Intent broadcastIntent = new Intent(MESSAGE);
|
Intent broadcastIntent = new Intent(MESSAGE_PODS_RECEIVED);
|
||||||
if (strings != null)
|
broadcastIntent.putExtra("pods", pods != null ? pods : new String[0]);
|
||||||
broadcastIntent.putExtra("pods", strings);
|
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(broadcastIntent);
|
||||||
sendBroadcast(broadcastIntent);
|
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue