Follow remote accounts
This commit is contained in:
parent
90cfcbb7ae
commit
860edec2e6
|
@ -99,9 +99,7 @@ public class AccountActivity extends AppCompatActivity {
|
||||||
|
|
||||||
instanceView.setText(account.getHost());
|
instanceView.setText(account.getHost());
|
||||||
FloatingActionButton edit_profile = findViewById(R.id.edit_profile);
|
FloatingActionButton edit_profile = findViewById(R.id.edit_profile);
|
||||||
edit_profile.setOnClickListener(v -> {
|
edit_profile.setOnClickListener(v -> startActivity(new Intent(AccountActivity.this, MyAccountActivity.class)));
|
||||||
startActivity(new Intent(AccountActivity.this, MyAccountActivity.class));
|
|
||||||
});
|
|
||||||
|
|
||||||
Button logout_button = findViewById(R.id.logout_button);
|
Button logout_button = findViewById(R.id.logout_button);
|
||||||
logout_button.setOnClickListener(v -> {
|
logout_button.setOnClickListener(v -> {
|
||||||
|
|
|
@ -121,7 +121,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private TypeOfConnection typeOfConnection;
|
public static TypeOfConnection typeOfConnection;
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
public static void showRadioButtonDialogFullInstances(Activity activity, boolean storeInDb) {
|
public static void showRadioButtonDialogFullInstances(Activity activity, boolean storeInDb) {
|
||||||
|
|
|
@ -17,8 +17,11 @@ package app.fedilab.fedilabtube;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
|
@ -54,10 +57,14 @@ import java.util.Map;
|
||||||
|
|
||||||
import app.fedilab.fedilabtube.client.APIResponse;
|
import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||||
|
import app.fedilab.fedilabtube.client.data.AccountData;
|
||||||
import app.fedilab.fedilabtube.client.data.ChannelData.Channel;
|
import app.fedilab.fedilabtube.client.data.ChannelData.Channel;
|
||||||
|
import app.fedilab.fedilabtube.drawer.OwnAccountsAdapter;
|
||||||
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
|
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
|
||||||
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
|
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
|
||||||
import app.fedilab.fedilabtube.helper.Helper;
|
import app.fedilab.fedilabtube.helper.Helper;
|
||||||
|
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||||
|
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||||
import app.fedilab.fedilabtube.viewmodel.RelationshipVM;
|
import app.fedilab.fedilabtube.viewmodel.RelationshipVM;
|
||||||
|
@ -65,6 +72,8 @@ import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
|
|
||||||
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
|
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
|
||||||
|
import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.NORMAL;
|
||||||
|
import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.SURFING;
|
||||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.FOLLOW;
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.FOLLOW;
|
||||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.MUTE;
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.MUTE;
|
||||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT;
|
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT;
|
||||||
|
@ -122,6 +131,57 @@ public class ShowChannelActivity extends AppCompatActivity {
|
||||||
ChannelsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(ChannelsVM.class);
|
ChannelsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(ChannelsVM.class);
|
||||||
viewModel.get(sepiaSearch ? peertubeInstance : null, CHANNEL, channelAcct == null ? channel.getAcct() : channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts);
|
viewModel.get(sepiaSearch ? peertubeInstance : null, CHANNEL, channelAcct == null ? channel.getAcct() : channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts);
|
||||||
manageChannel();
|
manageChannel();
|
||||||
|
|
||||||
|
if (MainActivity.typeOfConnection == MainActivity.TypeOfConnection.SURFING) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
int[][] states = new int[][]{
|
||||||
|
new int[]{android.R.attr.state_enabled}, // enabled
|
||||||
|
new int[]{-android.R.attr.state_enabled}, // disabled
|
||||||
|
new int[]{-android.R.attr.state_checked}, // unchecked
|
||||||
|
new int[]{android.R.attr.state_pressed} // pressed
|
||||||
|
};
|
||||||
|
|
||||||
|
int[] colors = new int[]{
|
||||||
|
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
|
||||||
|
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
|
||||||
|
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent()),
|
||||||
|
ContextCompat.getColor(ShowChannelActivity.this, Helper.getColorAccent())
|
||||||
|
};
|
||||||
|
account_follow.setBackgroundTintList(new ColorStateList(states, colors));
|
||||||
|
}
|
||||||
|
account_follow.setText(getString(R.string.action_follow));
|
||||||
|
account_follow.setEnabled(true);
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
List<AccountData.Account> accounts = new AccountDAO(ShowChannelActivity.this, db).getAllAccount();
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
account_follow.setVisibility(View.VISIBLE);
|
||||||
|
account_follow.setOnClickListener(v -> {
|
||||||
|
AlertDialog.Builder builderSingle = new AlertDialog.Builder(ShowChannelActivity.this);
|
||||||
|
builderSingle.setTitle(getString(R.string.list_of_accounts));
|
||||||
|
if (accounts != null) {
|
||||||
|
final OwnAccountsAdapter accountsListAdapter = new OwnAccountsAdapter(ShowChannelActivity.this, accounts);
|
||||||
|
builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> {
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(ShowChannelActivity.this, accounts.get(which).getHost(), accounts.get(which).getToken());
|
||||||
|
peertubeAPI.post(FOLLOW, channel.getAcct(), null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||||
|
builderSingle.show();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -312,7 +372,7 @@ public class ShowChannelActivity extends AppCompatActivity {
|
||||||
|
|
||||||
//Manages the visibility of the button
|
//Manages the visibility of the button
|
||||||
private void manageButtonVisibility() {
|
private void manageButtonVisibility() {
|
||||||
if (relationship == null)
|
if (relationship == null || MainActivity.typeOfConnection == SURFING)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
|
|
@ -100,15 +100,12 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.binding.aboutInstanceName.setText(aboutInstance.getName());
|
holder.binding.aboutInstanceName.setText(aboutInstance.getName());
|
||||||
holder.binding.playlistContainer.setOnClickListener(v -> {
|
holder.binding.instanceContainer.setOnClickListener(v -> {
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putString(Helper.PREF_INSTANCE, aboutInstance.getHost());
|
editor.putString(Helper.PREF_INSTANCE, aboutInstance.getHost());
|
||||||
editor.commit();
|
editor.commit();
|
||||||
((Activity) context).runOnUiThread(() -> {
|
Helper.logoutNoRemoval((Activity) context);
|
||||||
Intent intent = new Intent(context, MainActivity.class);
|
|
||||||
context.startActivity(intent);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
holder.binding.instanceMore.setOnClickListener(v -> {
|
holder.binding.instanceMore.setOnClickListener(v -> {
|
||||||
PopupMenu popup = new PopupMenu(context, holder.binding.instanceMore);
|
PopupMenu popup = new PopupMenu(context, holder.binding.instanceMore);
|
||||||
|
|
|
@ -639,7 +639,6 @@ public class Helper {
|
||||||
editor.putString(CLIENT_ID, null);
|
editor.putString(CLIENT_ID, null);
|
||||||
editor.putString(CLIENT_SECRET, null);
|
editor.putString(CLIENT_SECRET, null);
|
||||||
editor.putString(PREF_KEY_ID, null);
|
editor.putString(PREF_KEY_ID, null);
|
||||||
editor.putString(PREF_INSTANCE, null);
|
|
||||||
editor.putString(ID, null);
|
editor.putString(ID, null);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
Intent loginActivity = new Intent(activity, MainActivity.class);
|
Intent loginActivity = new Intent(activity, MainActivity.class);
|
||||||
|
|
|
@ -80,8 +80,11 @@ public class StoredInstanceDAO {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public boolean insertInstance(InstanceData.AboutInstance aboutInstance, String targetedInstance) {
|
public boolean insertInstance(InstanceData.AboutInstance aboutInstance, String targetedInstance) {
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
|
|
||||||
|
if (checkExists(targetedInstance)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
String instance = Helper.getLiveInstance(context);
|
String instance = Helper.getLiveInstance(context);
|
||||||
|
@ -90,7 +93,7 @@ public class StoredInstanceDAO {
|
||||||
values.put(Sqlite.COL_USER_INSTANCE, instance != null ? instance : "_ALL_");
|
values.put(Sqlite.COL_USER_INSTANCE, instance != null ? instance : "_ALL_");
|
||||||
values.put(Sqlite.COL_ABOUT, aboutInstanceToStringStorage(aboutInstance));
|
values.put(Sqlite.COL_ABOUT, aboutInstanceToStringStorage(aboutInstance));
|
||||||
values.put(Sqlite.COL_INSTANCE, targetedInstance);
|
values.put(Sqlite.COL_INSTANCE, targetedInstance);
|
||||||
//Inserts account
|
//Inserts instance
|
||||||
try {
|
try {
|
||||||
db.insertOrThrow(Sqlite.TABLE_BOOKMARKED_INSTANCES, null, values);
|
db.insertOrThrow(Sqlite.TABLE_BOOKMARKED_INSTANCES, null, values);
|
||||||
|
|
||||||
|
@ -101,6 +104,23 @@ public class StoredInstanceDAO {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if instance exists
|
||||||
|
*
|
||||||
|
* @param targetedInstance String
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private boolean checkExists(String targetedInstance) {
|
||||||
|
try {
|
||||||
|
Cursor c = db.query(Sqlite.TABLE_BOOKMARKED_INSTANCES, null, Sqlite.COL_INSTANCE + " = \"" + targetedInstance + "\"", null, null, null, null, "1");
|
||||||
|
return cursorToInstance(c) != null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert instance info in database
|
* Insert instance info in database
|
||||||
*
|
*
|
||||||
|
@ -108,6 +128,7 @@ public class StoredInstanceDAO {
|
||||||
* @param targetedInstance String
|
* @param targetedInstance String
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"unused", "RedundantSuppression"})
|
||||||
public int updateInstance(InstanceData.AboutInstance aboutInstance, String targetedInstance) {
|
public int updateInstance(InstanceData.AboutInstance aboutInstance, String targetedInstance) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(Sqlite.COL_ABOUT, aboutInstanceToStringStorage(aboutInstance));
|
values.put(Sqlite.COL_ABOUT, aboutInstanceToStringStorage(aboutInstance));
|
||||||
|
@ -146,9 +167,9 @@ public class StoredInstanceDAO {
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Method to hydrate an Account from database
|
* Method to hydrate an AboutInstance from database
|
||||||
* @param c Cursor
|
* @param c Cursor
|
||||||
* @return Account
|
* @return AboutInstance
|
||||||
*/
|
*/
|
||||||
private InstanceData.AboutInstance cursorToInstance(Cursor c) {
|
private InstanceData.AboutInstance cursorToInstance(Cursor c) {
|
||||||
//No element found
|
//No element found
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/playlist_container"
|
android:id="@+id/instance_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:divider="?android:dividerHorizontal"
|
android:divider="?android:dividerHorizontal"
|
||||||
|
|
Loading…
Reference in New Issue