multi account refactoring
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static ru.vtosters.lite.utils.Helper.GetContext;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.vk.audio.AudioMessageUtils;
|
||||
import com.vk.auth.api.VKAccount;
|
||||
import com.vk.core.f.FileUtils;
|
||||
import com.vk.core.util.AppContextHolder;
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vk.imageloader.VKImageLoader;
|
||||
import com.vk.pushes.PushSubscriber;
|
||||
import com.vtosters.lite.auth.VKAccountManager;
|
||||
import com.vtosters.lite.fragments.MaterialPreferenceToolbarFragment;
|
||||
import com.vtosters.lite.im.ImEngineProvider;
|
||||
|
||||
import ru.vtosters.lite.ui.PreferencesUtil;
|
||||
import ru.vtosters.lite.utils.AccountManager;
|
||||
import ru.vtosters.lite.utils.Helper;
|
||||
|
||||
public class AccountsFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
@Override
|
||||
public void b(Bundle bundle) {
|
||||
super.b(bundle);
|
||||
|
||||
int vtosterXml = Helper.GetContext().getResources().getIdentifier("empty", "xml", Helper.GetContext().getPackageName());
|
||||
this.a(vtosterXml);
|
||||
|
||||
PreferencesUtil.addPreferenceCategory(this, Helper.getString("accounts"));
|
||||
|
||||
PreferencesUtil.addListPreference(this, "account", "", Helper.getString("selectacc"), AccountManager.getAccAmountNames(), AccountManager.getAccAmount());
|
||||
|
||||
a("account").b(AccountManager.getCurrentAccountName());
|
||||
|
||||
a("account").a((preference, o) -> {
|
||||
VKImageLoader.b();
|
||||
ImEngineProvider.a().h();
|
||||
AudioMessageUtils.j();
|
||||
FileUtils.l();
|
||||
VKAccount b = VKAccountManager.b();
|
||||
PushSubscriber.a.a(b.b(), b.c());
|
||||
AppContextHolder.a.getSharedPreferences("gcm", 0).edit().clear().apply();
|
||||
ToastUtils.a(Helper.getString("restartapp"));
|
||||
return true;
|
||||
});
|
||||
|
||||
PreferencesUtil.addPreference(this, "newacc", Helper.getString("newacc"), "", null, preference -> {
|
||||
SharedPreferences sharedPrefs = GetContext().getSharedPreferences("com.vtosters.lite_preferences", MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPrefs.edit();
|
||||
editor.putString("account", Integer.toString(AccountManager.getAvalibleAcc()));
|
||||
editor.commit();
|
||||
|
||||
VKImageLoader.b();
|
||||
ImEngineProvider.a().h();
|
||||
AudioMessageUtils.j();
|
||||
FileUtils.l();
|
||||
VKAccount b = VKAccountManager.b();
|
||||
PushSubscriber.a.a(b.b(), b.c());
|
||||
AppContextHolder.a.getSharedPreferences("gcm", 0).edit().clear().apply();
|
||||
ToastUtils.a(Helper.getString("restartapp"));
|
||||
return false;
|
||||
});
|
||||
|
||||
PreferencesUtil.addPreference(this, "restartapp", Helper.getString("applicationrestart"), "", null, preference -> {
|
||||
Helper.restarting();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int aq() {
|
||||
return Helper.GetContext().getResources().getIdentifier("accounts", "string", Helper.GetContext().getPackageName());
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.a.ItemTouchHelper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package ru.vtosters.lite.ui.fragments.multiaccount;
|
||||
|
||||
class MultiAccountItem {
|
||||
public String nickname;
|
||||
public String imageUrl;
|
||||
public int index;
|
||||
|
||||
public MultiAccountItem(String name, String imageUrl, int index) {
|
||||
this.nickname = name;
|
||||
this.imageUrl = imageUrl;
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
package ru.vtosters.lite.ui.fragments.multiaccount;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
import static ru.vtosters.lite.utils.Helper.GetContext;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.vk.audio.AudioMessageUtils;
|
||||
import com.vk.auth.api.VKAccount;
|
||||
import com.vk.core.f.FileUtils;
|
||||
import com.vk.core.util.AppContextHolder;
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vk.imageloader.VKImageLoader;
|
||||
import com.vk.imageloader.view.VKCircleImageView;
|
||||
import com.vk.pushes.PushSubscriber;
|
||||
import com.vtosters.lite.auth.VKAccountManager;
|
||||
import com.vtosters.lite.im.ImEngineProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.utils.Helper;
|
||||
|
||||
public class MultiAccountAdapter extends RecyclerView.a<MultiAccountAdapter.MultiAccountViewHolder> {
|
||||
|
||||
private List<MultiAccountItem> mAccounts = new ArrayList<>();
|
||||
|
||||
public MultiAccountAdapter() {
|
||||
CharSequence[] getAccAmountNames = MultiAccountManager.getAccAmountNames();
|
||||
CharSequence[] getAccAmount = MultiAccountManager.getAccAmount();
|
||||
CharSequence[] getAvatars = MultiAccountManager.getAvatars();
|
||||
|
||||
for (int i = 0; i < getAccAmount.length; i++) {
|
||||
mAccounts.add(new MultiAccountItem((String) getAccAmountNames[i], (String) getAvatars[i], i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiAccountViewHolder b(ViewGroup parent, int viewType) {
|
||||
RelativeLayout layout = new RelativeLayout(parent.getContext());
|
||||
layout.setPadding(
|
||||
Helper.convertDpToPixel(6),
|
||||
Helper.convertDpToPixel(6),
|
||||
Helper.convertDpToPixel(6),
|
||||
Helper.convertDpToPixel(6)
|
||||
);
|
||||
|
||||
VKCircleImageView avatar = new VKCircleImageView(parent.getContext());
|
||||
avatar.setId(1);
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
Helper.convertDpToPixel(48),
|
||||
Helper.convertDpToPixel(48)
|
||||
);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
layout.addView(avatar, params);
|
||||
|
||||
TextView nickname = new TextView(parent.getContext());
|
||||
nickname.setId(2);
|
||||
nickname.setPaddingRelative(
|
||||
Helper.convertDpToPixel(12),
|
||||
0,
|
||||
0,
|
||||
0
|
||||
);
|
||||
nickname.setEllipsize(TextUtils.TruncateAt.END);
|
||||
nickname.setSingleLine(true);
|
||||
nickname.setTextSize(15.0f);
|
||||
nickname.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
|
||||
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(-2, -2);
|
||||
params1.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params1.addRule(RelativeLayout.RIGHT_OF, 1);
|
||||
layout.addView(nickname, params1);
|
||||
|
||||
ImageButton action = new ImageButton(parent.getContext());
|
||||
action.setId(3);
|
||||
action.setBackgroundResource(com.vtosters.lite.R.drawable.rounded_list_selector);
|
||||
action.setImageResource(com.vtosters.lite.R.drawable.ic_list_remove);
|
||||
action.setVisibility(View.INVISIBLE);
|
||||
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(
|
||||
Helper.convertDpToPixel(48),
|
||||
Helper.convertDpToPixel(48)
|
||||
);
|
||||
params2.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
layout.addView(action, params2);
|
||||
|
||||
return new MultiAccountViewHolder(layout);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void a(MultiAccountViewHolder holder, int pos) {
|
||||
holder.bind(mAccounts.get(pos == 0 ? null : pos - 1), pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int au_() {
|
||||
return mAccounts.size() + 1;
|
||||
}
|
||||
|
||||
static class MultiAccountViewHolder extends RecyclerView.x {
|
||||
|
||||
private RelativeLayout mContainer;
|
||||
private VKCircleImageView mAvatar;
|
||||
private TextView mNickname;
|
||||
private ImageButton mAction;
|
||||
|
||||
public MultiAccountViewHolder(View view) {
|
||||
super(view);
|
||||
|
||||
mContainer = (RelativeLayout) view;
|
||||
mAvatar = view.findViewById(1);
|
||||
mNickname = view.findViewById(2);
|
||||
mAction = view.findViewById(3);
|
||||
}
|
||||
|
||||
public void bind(MultiAccountItem item, int pos) {
|
||||
if (item == null) {
|
||||
mAvatar.setImageResource(com.vtosters.lite.R.drawable.ic_list_add);
|
||||
mNickname.setText("Добавить новый аккаунт");
|
||||
mContainer.setOnClickListener(v -> {
|
||||
SharedPreferences sharedPrefs = GetContext().getSharedPreferences("com.vtosters.lite_preferences", MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPrefs.edit();
|
||||
editor.putString("account", Integer.toString(MultiAccountManager.getAvalibleAcc()));
|
||||
editor.commit();
|
||||
|
||||
VKImageLoader.b();
|
||||
ImEngineProvider.a().h();
|
||||
AudioMessageUtils.j();
|
||||
FileUtils.l();
|
||||
VKAccount b = VKAccountManager.b();
|
||||
PushSubscriber.a.a(b.b(), b.c());
|
||||
AppContextHolder.a.getSharedPreferences("gcm", 0).edit().clear().apply();
|
||||
ToastUtils.a(Helper.getString("restartapp"));
|
||||
});
|
||||
} else {
|
||||
mContainer.setOnClickListener(v -> {
|
||||
// здесь выбор аккаунта
|
||||
VKImageLoader.b();
|
||||
ImEngineProvider.a().h();
|
||||
AudioMessageUtils.j();
|
||||
FileUtils.l();
|
||||
VKAccount b = VKAccountManager.b();
|
||||
PushSubscriber.a.a(b.b(), b.c());
|
||||
AppContextHolder.a.getSharedPreferences("gcm", 0).edit().clear().apply();
|
||||
});
|
||||
mAvatar.a(item.imageUrl);
|
||||
mNickname.setText(item.nickname);
|
||||
mAction.setOnClickListener(v -> {
|
||||
// здесь удаление аккаунта из префов
|
||||
VKImageLoader.b();
|
||||
ImEngineProvider.a().h();
|
||||
AudioMessageUtils.j();
|
||||
FileUtils.l();
|
||||
VKAccount b = VKAccountManager.b();
|
||||
PushSubscriber.a.a(b.b(), b.c());
|
||||
AppContextHolder.a.getSharedPreferences("gcm", 0).edit().clear().apply();
|
||||
ToastUtils.a(Helper.getString("restartapp"));
|
||||
});
|
||||
mAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package ru.vtosters.lite.ui.fragments.multiaccount;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import me.grishka.appkit.fragments.ToolbarFragment;
|
||||
|
||||
public class MultiAccountFragment extends ToolbarFragment {
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
private MultiAccountAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
public View d(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
||||
|
||||
LinearLayout layout = new LinearLayout(n());
|
||||
|
||||
mRecyclerView = new RecyclerView(n());
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(n()));
|
||||
mAdapter = new MultiAccountAdapter();
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
layout.addView(mRecyclerView, new LinearLayout.LayoutParams(-1, -1));
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(View arg0, Bundle arg1) {
|
||||
o_(true);
|
||||
|
||||
super.a(arg0, arg1);
|
||||
|
||||
a("Аккаунты");
|
||||
}
|
||||
}
|
||||
+29
-2
@@ -1,4 +1,4 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
package ru.vtosters.lite.ui.fragments.multiaccount;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static ru.vtosters.lite.utils.Helper.GetContext;
|
||||
@@ -9,7 +9,9 @@ import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AccountManager {
|
||||
import ru.vtosters.lite.utils.Helper;
|
||||
|
||||
public class MultiAccountManager {
|
||||
public static SharedPreferences getCurrentAccount() {
|
||||
String Value = ru.vtosters.lite.utils.Helper.GetPreferences().getString("account", "");
|
||||
return Helper.GetContext().getSharedPreferences("pref_account_manager" + Value, MODE_PRIVATE);
|
||||
@@ -43,6 +45,16 @@ public class AccountManager {
|
||||
return "err";
|
||||
}
|
||||
|
||||
public static String getAvatar(String str) {
|
||||
Pattern pattern = Pattern.compile(".*\"name\":\\{.*?:\"(.*?)\"\\}.*");
|
||||
Matcher matcher = pattern.matcher(getNeededAccount(str).getString("key_vk_account", ""));
|
||||
if (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
return group;
|
||||
}
|
||||
return "err";
|
||||
}
|
||||
|
||||
public static int getAvalibleAcc() {
|
||||
int intg = 0;
|
||||
while (true) {
|
||||
@@ -71,6 +83,21 @@ public class AccountManager {
|
||||
return charSequenceItems;
|
||||
}
|
||||
|
||||
public static CharSequence[] getAvatars() {
|
||||
int intg = 0;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while (true) {
|
||||
if (getAvatar(Integer.toString(intg)) != "err") {
|
||||
list.add(getName(Integer.toString(intg)));
|
||||
intg++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
};
|
||||
final CharSequence[] charSequenceItems = list.toArray(new CharSequence[list.size()]);
|
||||
return charSequenceItems;
|
||||
}
|
||||
|
||||
public static CharSequence[] getAccAmount() {
|
||||
int intg = 0;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
@@ -58,6 +58,7 @@ import java.util.Scanner;
|
||||
|
||||
import kotlin.jvm.internal.Intrinsics;
|
||||
import ru.vtosters.lite.ui.fragments.dockbar.DockBarManager;
|
||||
import ru.vtosters.lite.ui.fragments.multiaccount.MultiAccountManager;
|
||||
|
||||
public class Prefs {
|
||||
public static String VERSIONNAME = "2.0 DEV";
|
||||
@@ -710,7 +711,7 @@ public class Prefs {
|
||||
setupFilters();
|
||||
fixGapps();
|
||||
setProxy();
|
||||
AccountManager.MigrateToNewType();
|
||||
MultiAccountManager.MigrateToNewType();
|
||||
registerActivities(application);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_READ"/>
|
||||
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_WRITE"/>
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
|
||||
<application android:allowBackup="false" android:debuggable="false" android:hardwareAccelerated="true" android:icon="@mipmap/vt_launcher" android:label="@string/app_name" android:largeHeap="true" android:requestLegacyExternalStorage="true" android:preserveLegacyExternalStorage="true" android:name="com.vtosters.lite.VKApplication" android:networkSecurityConfig="@xml/network_security_config" android:resizeableActivity="true" android:roundIcon="@mipmap/vt_launcher_round" android:supportsRtl="true" android:theme="@style/BaseStyle">
|
||||
<application android:allowBackup="false" android:debuggable="true" android:hardwareAccelerated="true" android:icon="@mipmap/vt_launcher" android:label="@string/app_name" android:largeHeap="true" android:requestLegacyExternalStorage="true" android:preserveLegacyExternalStorage="true" android:name="com.vtosters.lite.VKApplication" android:networkSecurityConfig="@xml/network_security_config" android:resizeableActivity="true" android:roundIcon="@mipmap/vt_launcher_round" android:supportsRtl="true" android:theme="@style/BaseStyle">
|
||||
<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyBlTHhNGPj7ktPWrUo_d4YJs_Sn_zsISZg"/>
|
||||
<meta-data android:name="com.google.android.geo.API_SECRET" android:value="yu6ZAA0OWO3kmr4es7fGtSmiyfk="/>
|
||||
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id"/>
|
||||
|
||||
@@ -4257,7 +4257,7 @@
|
||||
.line 14
|
||||
new-instance v8, Lcom/vk/navigation/Navigator;
|
||||
|
||||
const-class v0, Lru/vtosters/lite/ui/fragments/AccountsFragment;
|
||||
const-class v0, Lru/vtosters/lite/ui/fragments/multiaccount/MultiAccountFragment;
|
||||
|
||||
invoke-direct {v8, v0}, Lcom/vk/navigation/Navigator;-><init>(Ljava/lang/Class;)V
|
||||
|
||||
|
||||
@@ -587,7 +587,7 @@
|
||||
.method public static e()Landroid/content/SharedPreferences;
|
||||
.locals 3
|
||||
|
||||
invoke-static {}, Lru/vtosters/lite/utils/AccountManager;->getCurrentAccount()Landroid/content/SharedPreferences;
|
||||
invoke-static {}, Lru/vtosters/lite/ui/fragments/multiaccount/MultiAccountManager;->getCurrentAccount()Landroid/content/SharedPreferences;
|
||||
|
||||
move-result-object v0
|
||||
|
||||
|
||||
@@ -1162,7 +1162,7 @@
|
||||
|
||||
move-result-object v8
|
||||
|
||||
const-class v9, Lru/vtosters/lite/ui/fragments/AccountsFragment;
|
||||
const-class v9, Lru/vtosters/lite/ui/fragments/multiaccount/MultiAccountFragment;
|
||||
|
||||
invoke-direct {v5, v6, v7, v8, v9}, Lcom/vtosters/lite/fragments/SettingsListFragment$a;-><init>(IILjava/lang/Object;Ljava/lang/Class;)V
|
||||
|
||||
|
||||
Reference in New Issue
Block a user