Fix issue #241 - Store instance info in sharedpref
This commit is contained in:
parent
1437976f38
commit
13d8876626
|
@ -786,7 +786,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getEmoji(currentInstance);
|
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getEmoji(currentInstance);
|
||||||
//Retrieve instance info
|
//Retrieve instance info
|
||||||
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getInstance(currentInstance)
|
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getInstance(currentInstance)
|
||||||
.observe(BaseMainActivity.this, instance -> instanceInfo = instance.info);
|
.observe(BaseMainActivity.this, instance -> {
|
||||||
|
instanceInfo = instance.info;
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putString(getString(R.string.INSTANCE_INFO) + MainActivity.currentInstance, Instance.serialize(instanceInfo));
|
||||||
|
editor.apply();
|
||||||
|
});
|
||||||
//Retrieve filters
|
//Retrieve filters
|
||||||
new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getFilters(currentInstance, currentToken)
|
new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getFilters(currentInstance, currentToken)
|
||||||
.observe(BaseMainActivity.this, filters -> mainFilters = filters);
|
.observe(BaseMainActivity.this, filters -> mainFilters = filters);
|
||||||
|
|
|
@ -26,6 +26,7 @@ import android.content.BroadcastReceiver;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -48,6 +49,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.work.Data;
|
import androidx.work.Data;
|
||||||
import androidx.work.OneTimeWorkRequest;
|
import androidx.work.OneTimeWorkRequest;
|
||||||
|
@ -69,6 +71,7 @@ import app.fedilab.android.R;
|
||||||
import app.fedilab.android.client.entities.api.Attachment;
|
import app.fedilab.android.client.entities.api.Attachment;
|
||||||
import app.fedilab.android.client.entities.api.Context;
|
import app.fedilab.android.client.entities.api.Context;
|
||||||
import app.fedilab.android.client.entities.api.EmojiInstance;
|
import app.fedilab.android.client.entities.api.EmojiInstance;
|
||||||
|
import app.fedilab.android.client.entities.api.Instance;
|
||||||
import app.fedilab.android.client.entities.api.Mention;
|
import app.fedilab.android.client.entities.api.Mention;
|
||||||
import app.fedilab.android.client.entities.api.ScheduledStatus;
|
import app.fedilab.android.client.entities.api.ScheduledStatus;
|
||||||
import app.fedilab.android.client.entities.api.Status;
|
import app.fedilab.android.client.entities.api.Status;
|
||||||
|
@ -234,6 +237,14 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ComposeActivity.this);
|
||||||
|
if (MainActivity.instanceInfo == null) {
|
||||||
|
String instanceInfo = sharedpreferences.getString(getString(R.string.INSTANCE_INFO) + instance, null);
|
||||||
|
if (instanceInfo != null) {
|
||||||
|
MainActivity.instanceInfo = Instance.restore(instanceInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StatusesVM statusesVM = new ViewModelProvider(ComposeActivity.this).get(StatusesVM.class);
|
StatusesVM statusesVM = new ViewModelProvider(ComposeActivity.this).get(StatusesVM.class);
|
||||||
//Empty compose
|
//Empty compose
|
||||||
List<Status> statusDraftList = new ArrayList<>();
|
List<Status> statusDraftList = new ArrayList<>();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package app.fedilab.android.client.entities.api;
|
package app.fedilab.android.client.entities.api;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -113,6 +114,25 @@ public class Instance implements Serializable {
|
||||||
return mimeTypes;
|
return mimeTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String serialize(Instance instance) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
try {
|
||||||
|
return gson.toJson(instance);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Instance restore(String serialized) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
try {
|
||||||
|
return gson.fromJson(serialized, Instance.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Configuration implements Serializable {
|
public static class Configuration implements Serializable {
|
||||||
@SerializedName("statuses")
|
@SerializedName("statuses")
|
||||||
public StatusesConf statusesConf;
|
public StatusesConf statusesConf;
|
||||||
|
|
|
@ -895,7 +895,7 @@
|
||||||
<string name="SET_ACCOUNTS_PER_CALL" translatable="false">SET_ACCOUNTS_PER_CALL</string>
|
<string name="SET_ACCOUNTS_PER_CALL" translatable="false">SET_ACCOUNTS_PER_CALL</string>
|
||||||
<string name="SET_STATUSES_PER_CALL" translatable="false">SET_STATUSES_PER_CALL</string>
|
<string name="SET_STATUSES_PER_CALL" translatable="false">SET_STATUSES_PER_CALL</string>
|
||||||
<string name="SET_NOTIFICATIONS_PER_CALL" translatable="false">SET_NOTIFICATIONS_PER_CALL</string>
|
<string name="SET_NOTIFICATIONS_PER_CALL" translatable="false">SET_NOTIFICATIONS_PER_CALL</string>
|
||||||
|
<string name="INSTANCE_INFO" translatable="false">INSTANCE_INFO</string>
|
||||||
<string name="SET_INVIDIOUS" translatable="false">SET_INVIDIOUS</string>
|
<string name="SET_INVIDIOUS" translatable="false">SET_INVIDIOUS</string>
|
||||||
<string name="SET_INVIDIOUS_HOST" translatable="false">SET_INVIDIOUS_HOST</string>
|
<string name="SET_INVIDIOUS_HOST" translatable="false">SET_INVIDIOUS_HOST</string>
|
||||||
<string name="DEFAULT_INVIDIOUS_HOST" translatable="false">invidious.snopyta.org</string>
|
<string name="DEFAULT_INVIDIOUS_HOST" translatable="false">invidious.snopyta.org</string>
|
||||||
|
|
Loading…
Reference in New Issue