Some changes

This commit is contained in:
Thomas 2023-03-15 15:23:12 +01:00
parent dddef9706d
commit ffe7dbf1dd
9 changed files with 301 additions and 187 deletions

View file

@ -24,6 +24,7 @@ import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
import static app.fedilab.android.mastodon.helper.Helper.displayReleaseNotesIfNeeded;
import static app.fedilab.android.mastodon.helper.ThemeHelper.fetchAccentColor;
import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.sendAction;
import static app.fedilab.android.peertube.activities.PeertubeMainActivity.typeOfConnection;
import android.Manifest;
import android.annotation.SuppressLint;
@ -374,6 +375,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} else if (accounts.get(0).peertube_account != null) {
account = "@" + accounts.get(0).peertube_account.getAcct() + "@" + accounts.get(0).instance;
}
typeOfConnection = PeertubeMainActivity.TypeOfConnection.NORMAL;
Toasty.info(activity, activity.getString(R.string.toast_account_changed, account), Toasty.LENGTH_LONG).show();
BaseMainActivity.currentToken = accounts.get(0).token;
BaseMainActivity.currentUserID = accounts.get(0).user_id;
@ -546,6 +548,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} else if (account.peertube_account != null) {
acctForAccount = "@" + account.peertube_account.getUsername() + "@" + account.instance;
}
typeOfConnection = PeertubeMainActivity.TypeOfConnection.NORMAL;
Toasty.info(activity, activity.getString(R.string.toast_account_changed, acctForAccount), Toasty.LENGTH_LONG).show();
BaseMainActivity.currentToken = account.token;
BaseMainActivity.currentUserID = account.user_id;
@ -559,6 +562,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
editor.commit();
//The user is now aut
//The user is now authenticated, it will be redirected to MainActivity
Intent mainActivity = new Intent(activity, MainActivity.class);
activity.startActivity(mainActivity);
activity.finish();
@ -711,6 +715,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} else if (account.peertube_account != null) {
acct = "@" + account.peertube_account.getUsername() + "@" + account.instance;
}
typeOfConnection = PeertubeMainActivity.TypeOfConnection.NORMAL;
Toasty.info(activity, activity.getString(R.string.toast_account_changed, acct), Toasty.LENGTH_LONG).show();
BaseMainActivity.currentToken = account.token;
BaseMainActivity.currentUserID = account.user_id;
@ -1358,6 +1363,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
bundle.putBoolean(Helper.ARG_PEERTUBE_NAV_REMOTE, true);
intent.putExtras(bundle);
startActivity(intent);
finish();
} else if (id == R.id.nav_about_instance) {
(new InstanceActivity()).show(getSupportFragmentManager(), null);
}

View file

@ -302,6 +302,9 @@ public class Helper {
public static final String PREF_USER_TOKEN = "PREF_USER_TOKEN";
public static final String PREF_USER_ID = "PREF_USER_ID";
public static final String PREF_USER_INSTANCE = "PREF_USER_INSTANCE";
public static final String PREF_USER_INSTANCE_PEERTUBE_BROWSING = "PREF_USER_INSTANCE_PEERTUBE_BROWSING";
public static final String PREF_USER_SOFTWARE = "PREF_USER_SOFTWARE";
public static final String PREF_IS_MODERATOR = "PREF_IS_MODERATOR";
public static final String PREF_IS_ADMINISTRATOR = "PREF_IS_ADMINISTRATOR";

View file

@ -14,7 +14,7 @@ package app.fedilab.android.peertube.activities;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING;
import static app.fedilab.android.mastodon.helper.Helper.addFragment;
import static app.fedilab.android.peertube.activities.PeertubeMainActivity.INSTANCE_ADDRESS;
import static app.fedilab.android.peertube.activities.PeertubeMainActivity.PICK_INSTANCE;
@ -32,6 +32,8 @@ import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -65,33 +67,8 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns
private AboutInstanceAdapter aboutInstanceAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityManageInstancesPeertubeBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
binding.loader.setVisibility(View.VISIBLE);
binding.noAction.setVisibility(View.GONE);
binding.lvInstances.setVisibility(View.GONE);
binding.actionButton.setOnClickListener(v -> showRadioButtonDialogFullInstances(ManageInstancesActivity.this));
aboutInstances = new ArrayList<>();
aboutInstanceAdapter = new AboutInstanceAdapter(this.aboutInstances);
aboutInstanceAdapter.allInstancesRemoved = this;
binding.lvInstances.setAdapter(aboutInstanceAdapter);
LinearLayoutManager layoutManager
= new LinearLayoutManager(ManageInstancesActivity.this);
binding.lvInstances.setLayoutManager(layoutManager);
InfoInstanceVM viewModelInfoInstance = new ViewModelProvider(ManageInstancesActivity.this).get(InfoInstanceVM.class);
viewModelInfoInstance.getInstances().observe(ManageInstancesActivity.this, this::manageVIewInfoInstance);
}
@SuppressLint("ApplySharedPref")
private void showRadioButtonDialogFullInstances(Activity activity) {
public static void showRadioButtonDialogFullInstances(Activity activity, FragmentManager fragmentManager) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(activity);
alt_bld.setTitle(R.string.instance_choice);
@ -116,7 +93,7 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns
WellKnownNodeinfo.NodeInfo instanceNodeInfo = new RetrofitPeertubeAPI(activity, newInstance, null).getNodeInfo();
if (instanceNodeInfo.getSoftware() != null && instanceNodeInfo.getSoftware().getName().trim().toLowerCase().compareTo("peertube") == 0) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(PREF_USER_INSTANCE, newInstance);
editor.putString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, newInstance);
editor.commit();
newInstance = newInstance.trim().toLowerCase();
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(activity, newInstance, null).getAboutInstance();
@ -136,24 +113,49 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns
}).start());
alt_bld.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
alt_bld.setNeutralButton(R.string.help, (dialog, which) -> {
getSupportFragmentManager().setFragmentResultListener(PICK_INSTANCE, this, (requestKey, result) -> {
fragmentManager.setFragmentResultListener(PICK_INSTANCE, (LifecycleOwner) activity, (requestKey, result) -> {
new Thread(() -> {
String newInstance = result.getString(INSTANCE_ADDRESS);
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(ManageInstancesActivity.this, newInstance, null).getAboutInstance();
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StoredInstanceDAO(ManageInstancesActivity.this, db).insertInstance(aboutInstance, newInstance);
runOnUiThread(() -> new Handler().post(() -> Helper.logoutNoRemoval(ManageInstancesActivity.this)));
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(activity, newInstance, null).getAboutInstance();
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StoredInstanceDAO(activity, db).insertInstance(aboutInstance, newInstance);
activity.runOnUiThread(() -> new Handler().post(() -> Helper.logoutNoRemoval(activity)));
}).start();
getSupportFragmentManager().clearFragmentResultListener(PICK_INSTANCE);
fragmentManager.clearFragmentResultListener(PICK_INSTANCE);
});
addFragment(
getSupportFragmentManager(), android.R.id.content, new FragmentLoginPickInstancePeertube(),
fragmentManager, android.R.id.content, new FragmentLoginPickInstancePeertube(),
null, null, FragmentLoginPickInstancePeertube.class.getName());
});
AlertDialog alert = alt_bld.create();
alert.show();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityManageInstancesPeertubeBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
binding.loader.setVisibility(View.VISIBLE);
binding.noAction.setVisibility(View.GONE);
binding.lvInstances.setVisibility(View.GONE);
binding.actionButton.setOnClickListener(v -> showRadioButtonDialogFullInstances(ManageInstancesActivity.this, getSupportFragmentManager()));
aboutInstances = new ArrayList<>();
aboutInstanceAdapter = new AboutInstanceAdapter(this.aboutInstances);
aboutInstanceAdapter.allInstancesRemoved = this;
binding.lvInstances.setAdapter(aboutInstanceAdapter);
LinearLayoutManager layoutManager
= new LinearLayoutManager(ManageInstancesActivity.this);
binding.lvInstances.setLayoutManager(layoutManager);
InfoInstanceVM viewModelInfoInstance = new ViewModelProvider(ManageInstancesActivity.this).get(InfoInstanceVM.class);
viewModelInfoInstance.getInstances().observe(ManageInstancesActivity.this, this::manageVIewInfoInstance);
}
private void manageVIewInfoInstance(List<InstanceData.AboutInstance> aboutInstances) {
binding.loader.setVisibility(View.GONE);
if (aboutInstances == null || aboutInstances.size() == 0) {

View file

@ -127,7 +127,6 @@ import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.activities.BasePeertubeActivity;
import app.fedilab.android.databinding.ActivityPeertubeBinding;
@ -591,7 +590,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
private void playVideo() {
if (status == null && typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) {
app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM searchVM = new ViewModelProvider(PeertubeActivity.this).get(app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM.class);
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, videoUuid, null, "statuses", false, true, false, 0, null, null, 1)
searchVM.search(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), videoUuid, null, "statuses", false, true, false, 0, null, null, 1)
.observe(PeertubeActivity.this, results -> {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
status = results.statuses.get(0);
@ -1041,7 +1040,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
}
alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> {
if (status.reblogged) {
statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id)
statusesVM.unReblog(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;
@ -1050,7 +1049,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
});
} else {
((SparkButton) v).playAnimation();
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null)
statusesVM.reblog(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id, null)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;
@ -1065,7 +1064,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
alert.show();
} else {
if (status.reblogged) {
statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id)
statusesVM.unReblog(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;
@ -1074,7 +1073,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
});
} else {
((SparkButton) v).playAnimation();
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null)
statusesVM.reblog(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id, null)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;
@ -1099,7 +1098,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
}
alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> {
if (status.favourited) {
statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id)
statusesVM.unFavourite(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;
@ -1108,7 +1107,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
});
} else {
((SparkButton) v).playAnimation();
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id)
statusesVM.favourite(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;
@ -1123,7 +1122,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
alert.show();
} else {
if (status.favourited) {
statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id)
statusesVM.unFavourite(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;
@ -1132,7 +1131,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
});
} else {
((SparkButton) v).playAnimation();
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id)
statusesVM.favourite(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;
@ -1148,7 +1147,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
if (status != null) {
StatusesVM statusesVM = new ViewModelProvider(PeertubeActivity.this).get(StatusesVM.class);
if (status.bookmarked) {
statusesVM.unBookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id)
statusesVM.unBookmark(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;
@ -1157,7 +1156,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
});
} else {
((SparkButton) v).playAnimation();
statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id)
statusesVM.bookmark(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id)
.observe(PeertubeActivity.this, _status -> {
if (_status != null) {
status = _status;

View file

@ -25,6 +25,7 @@ import static app.fedilab.android.BaseMainActivity.mamageNewIntent;
import static app.fedilab.android.BaseMainActivity.manageDrawerMenu;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN;
import static app.fedilab.android.mastodon.helper.Helper.addFragment;
@ -34,11 +35,13 @@ import static app.fedilab.android.peertube.helper.SwitchAccountHelper.switchDial
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
@ -96,7 +99,9 @@ import app.fedilab.android.peertube.fragment.FragmentLoginPickInstancePeertube;
import app.fedilab.android.peertube.helper.Helper;
import app.fedilab.android.peertube.helper.HelperInstance;
import app.fedilab.android.peertube.services.RetrieveInfoService;
import app.fedilab.android.peertube.sqlite.StoredInstanceDAO;
import app.fedilab.android.peertube.viewmodel.TimelineVM;
import app.fedilab.android.sqlite.Sqlite;
public class PeertubeMainActivity extends PeertubeBaseMainActivity {
@ -165,13 +170,35 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
if (extras != null && extras.containsKey(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE)) {
if (extras.getBoolean(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE)) {
typeOfConnection = PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT;
intentActvity.removeExtra(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE);
}
}
}
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this);
if (typeOfConnection == TypeOfConnection.REMOTE_ACCOUNT) {
String defaultInstance = sharedpreferences.getString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, null);
Log.v(app.fedilab.android.mastodon.helper.Helper.TAG, "defaultInstance-->: " + defaultInstance);
if (defaultInstance == null) {
getSupportFragmentManager().setFragmentResultListener(PICK_INSTANCE, PeertubeMainActivity.this, (requestKey, result) -> {
new Thread(() -> {
String newInstance = result.getString(INSTANCE_ADDRESS);
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(PeertubeMainActivity.this, newInstance, null).getAboutInstance();
SQLiteDatabase db = Sqlite.getInstance(PeertubeMainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StoredInstanceDAO(PeertubeMainActivity.this, db).insertInstance(aboutInstance, newInstance);
}).start();
getSupportFragmentManager().clearFragmentResultListener(PICK_INSTANCE);
});
addFragment(
getSupportFragmentManager(), android.R.id.content, new FragmentLoginPickInstancePeertube(),
null, null, FragmentLoginPickInstancePeertube.class.getName());
}
return;
}
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this);
badgeCount = 0;
headerMenuOpen = false;
@ -207,148 +234,153 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater());
currentAccount = null;
new Thread(() -> {
try {
if (currentToken == null) {
currentToken = sharedpreferences.getString(app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN, null);
}
currentAccount = new Account(PeertubeMainActivity.this).getConnectedAccount();
if (currentAccount == null) {
if (currentUserID == null) {
currentUserID = sharedpreferences.getString(PREF_USER_ID, null);
}
if (currentInstance == null) {
currentInstance = sharedpreferences.getString(PREF_USER_INSTANCE, null);
}
currentAccount = new Account(PeertubeMainActivity.this).getUniqAccount(currentUserID, currentInstance);
}
} catch (DBException e) {
e.printStackTrace();
}
if (currentAccount != null && currentAccount.mastodon_account != null && typeOfConnection != TypeOfConnection.REMOTE_ACCOUNT) {
//It is a Mastodon User
Intent myIntent = new Intent(PeertubeMainActivity.this, MainActivity.class);
startActivity(myIntent);
finish();
return;
}
//If the attached account is null, the app will fetch remote instance to get up-to-date values
if (currentAccount != null && currentAccount.peertube_account == null) {
if (Helper.isLoggedIn()) {
new Thread(() -> {
try {
userMe = new RetrofitPeertubeAPI(PeertubeMainActivity.this, currentInstance, currentToken).verifyCredentials();
currentAccount.peertube_account = userMe.getAccount();
} catch (Error e) {
if (currentToken == null) {
currentToken = sharedpreferences.getString(app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN, null);
}
currentAccount = new Account(PeertubeMainActivity.this).getConnectedAccount();
if (currentAccount == null) {
if (currentUserID == null) {
currentUserID = sharedpreferences.getString(PREF_USER_ID, null);
}
if (currentInstance == null) {
currentInstance = sharedpreferences.getString(PREF_USER_INSTANCE, null);
}
currentAccount = new Account(PeertubeMainActivity.this).getUniqAccount(currentUserID, currentInstance);
}
} catch (DBException e) {
e.printStackTrace();
}
}
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (typeOfConnection == TypeOfConnection.REMOTE_ACCOUNT) {
headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.mastodon_account.username, currentAccount.instance));
if (currentAccount.mastodon_account.display_name == null || currentAccount.mastodon_account.display_name.isEmpty()) {
currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct;
}
headerMainBinding.accountName.setText(currentAccount.mastodon_account.display_name);
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
headerMainBinding.accountName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
headerMainBinding.accountAcc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
app.fedilab.android.mastodon.helper.Helper.loadPP(PeertubeMainActivity.this, headerMainBinding.accountProfilePicture, currentAccount, false);
headerMainBinding.backgroundImage.setAlpha(0.5f);
headerMainBinding.accountAcc.setOnClickListener(v -> headerMainBinding.changeAccount.callOnClick());
headerMainBinding.changeAccount.setOnClickListener(v -> {
headerMenuOpen = !headerMenuOpen;
manageDrawerMenu(PeertubeMainActivity.this, binding.drawerNavView, headerMainBinding);
});
} else {
headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.peertube_account.getUsername(), currentAccount.instance));
if (currentAccount.peertube_account.getDisplayName() == null || currentAccount.peertube_account.getDisplayName().isEmpty()) {
currentAccount.peertube_account.setDisplayName(currentAccount.peertube_account.getAcct());
}
headerMainBinding.accountName.setText(currentAccount.peertube_account.getDisplayName());
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
headerMainBinding.accountName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
headerMainBinding.accountAcc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
app.fedilab.android.mastodon.helper.Helper.loadPP(PeertubeMainActivity.this, headerMainBinding.accountProfilePicture, currentAccount, false);
headerMainBinding.backgroundImage.setAlpha(0.5f);
headerMainBinding.accountAcc.setOnClickListener(v -> headerMainBinding.changeAccount.callOnClick());
headerMainBinding.changeAccount.setOnClickListener(v -> {
headerMenuOpen = !headerMenuOpen;
manageDrawerMenu(PeertubeMainActivity.this, binding.drawerNavView, headerMainBinding);
});
if (currentAccount != null && currentAccount.mastodon_account != null && typeOfConnection != TypeOfConnection.REMOTE_ACCOUNT) {
//It is a Mastodon User
Intent myIntent = new Intent(PeertubeMainActivity.this, MainActivity.class);
startActivity(myIntent);
finish();
return;
}
//If the attached account is null, the app will fetch remote instance to get up-to-date values
if (currentAccount != null && currentAccount.peertube_account == null) {
try {
userMe = new RetrofitPeertubeAPI(PeertubeMainActivity.this, currentInstance, currentToken).verifyCredentials();
currentAccount.peertube_account = userMe.getAccount();
} catch (Error e) {
e.printStackTrace();
}
}
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (typeOfConnection == TypeOfConnection.REMOTE_ACCOUNT) {
headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.mastodon_account.username, currentAccount.instance));
if (currentAccount.mastodon_account.display_name == null || currentAccount.mastodon_account.display_name.isEmpty()) {
currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct;
}
headerMainBinding.accountName.setText(currentAccount.mastodon_account.display_name);
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
headerMainBinding.accountName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
headerMainBinding.accountAcc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
app.fedilab.android.mastodon.helper.Helper.loadPP(PeertubeMainActivity.this, headerMainBinding.accountProfilePicture, currentAccount, false);
headerMainBinding.backgroundImage.setAlpha(0.5f);
headerMainBinding.accountAcc.setOnClickListener(v -> headerMainBinding.changeAccount.callOnClick());
headerMainBinding.changeAccount.setOnClickListener(v -> {
if (Helper.isLoggedIn()) {
headerMenuOpen = !headerMenuOpen;
manageDrawerMenu(PeertubeMainActivity.this, binding.drawerNavView, headerMainBinding);
});
} else {
headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.peertube_account.getUsername(), currentAccount.instance));
if (currentAccount.peertube_account.getDisplayName() == null || currentAccount.peertube_account.getDisplayName().isEmpty()) {
currentAccount.peertube_account.setDisplayName(currentAccount.peertube_account.getAcct());
}
headerMainBinding.accountName.setText(currentAccount.peertube_account.getDisplayName());
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
headerMainBinding.accountName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
headerMainBinding.accountAcc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
app.fedilab.android.mastodon.helper.Helper.loadPP(PeertubeMainActivity.this, headerMainBinding.accountProfilePicture, currentAccount, false);
headerMainBinding.backgroundImage.setAlpha(0.5f);
headerMainBinding.accountAcc.setOnClickListener(v -> headerMainBinding.changeAccount.callOnClick());
headerMainBinding.changeAccount.setOnClickListener(v -> {
headerMenuOpen = !headerMenuOpen;
manageDrawerMenu(PeertubeMainActivity.this, binding.drawerNavView, headerMainBinding);
});
}
binding.navView.inflateMenu(R.menu.bottom_nav_menu_connected_peertube);
refreshToken();
} else {
binding.navView.inflateMenu(R.menu.bottom_nav_menu);
}
};
mainHandler.post(myRunnable);
}).start();
};
mainHandler.post(myRunnable);
}).start();
} else {
binding.navView.inflateMenu(R.menu.bottom_nav_menu_peertube);
}
headerMainBinding.instanceInfo.setVisibility(View.GONE);
headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(PeertubeMainActivity.this, headerMainBinding, getSupportFragmentManager()));
binding.drawerNavView.addHeaderView(headerMainBinding.getRoot());
binding.drawerNavView.setNavigationItemSelectedListener(item -> {
if (item.getItemId() == R.id.action_settings) {
Intent intent = new Intent(PeertubeMainActivity.this, SettingsActivity.class);
startActivity(intent);
} else if (item.getItemId() == R.id.action_account) {
Intent intent;
if (typeOfConnection == TypeOfConnection.SURFING) {
switchDialog(PeertubeMainActivity.this, false);
} else {
if (Helper.canMakeAction()) {
intent = new Intent(PeertubeMainActivity.this, AccountActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
if (Helper.isLoggedIn()) {
binding.drawerNavView.addHeaderView(headerMainBinding.getRoot());
binding.drawerNavView.setNavigationItemSelectedListener(item -> {
if (item.getItemId() == R.id.action_settings) {
Intent intent = new Intent(PeertubeMainActivity.this, SettingsActivity.class);
startActivity(intent);
} else if (item.getItemId() == R.id.action_account) {
Intent intent;
if (typeOfConnection == TypeOfConnection.SURFING || typeOfConnection == TypeOfConnection.REMOTE_ACCOUNT) {
switchDialog(PeertubeMainActivity.this, false);
} else {
intent = new Intent(PeertubeMainActivity.this, LoginActivity.class);
startActivity(intent);
}
if (Helper.canMakeAction()) {
intent = new Intent(PeertubeMainActivity.this, AccountActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
} else {
intent = new Intent(PeertubeMainActivity.this, LoginActivity.class);
startActivity(intent);
}
}
} else if (item.getItemId() == R.id.action_upload) {
Intent intent = new Intent(PeertubeMainActivity.this, PeertubeUploadActivity.class);
startActivity(intent);
} else if (item.getItemId() == R.id.action_myvideos) {
Intent intent = new Intent(PeertubeMainActivity.this, VideosTimelineActivity.class);
Bundle bundledrawer = new Bundle();
bundledrawer.putSerializable("type", TimelineVM.TimelineType.MY_VIDEOS);
intent.putExtras(bundledrawer);
startActivity(intent);
} else if (item.getItemId() == R.id.action_history) {
Intent intent = new Intent(PeertubeMainActivity.this, VideosTimelineActivity.class);
Bundle bundledrawer = new Bundle();
bundledrawer.putSerializable("type", TimelineVM.TimelineType.HISTORY);
intent.putExtras(bundledrawer);
startActivity(intent);
} else if (item.getItemId() == R.id.action_most_liked) {
Intent intent = new Intent(PeertubeMainActivity.this, VideosTimelineActivity.class);
Bundle bundledrawer = new Bundle();
bundledrawer.putSerializable("type", TimelineVM.TimelineType.MOST_LIKED);
intent.putExtras(bundledrawer);
startActivity(intent);
} else if (item.getItemId() == R.id.action_playlist) {
Intent intent;
intent = new Intent(PeertubeMainActivity.this, AllPlaylistsActivity.class);
startActivity(intent);
} else if (item.getItemId() == R.id.action_sepia_search) {
Intent intent = new Intent(PeertubeMainActivity.this, SepiaSearchActivity.class);
startActivity(intent);
} else if (item.getItemId() == R.id.action_about) {
Intent intent = new Intent(PeertubeMainActivity.this, AboutActivity.class);
startActivity(intent);
}
} else if (item.getItemId() == R.id.action_upload) {
Intent intent = new Intent(PeertubeMainActivity.this, PeertubeUploadActivity.class);
startActivity(intent);
} else if (item.getItemId() == R.id.action_myvideos) {
Intent intent = new Intent(PeertubeMainActivity.this, VideosTimelineActivity.class);
Bundle bundledrawer = new Bundle();
bundledrawer.putSerializable("type", TimelineVM.TimelineType.MY_VIDEOS);
intent.putExtras(bundledrawer);
startActivity(intent);
} else if (item.getItemId() == R.id.action_history) {
Intent intent = new Intent(PeertubeMainActivity.this, VideosTimelineActivity.class);
Bundle bundledrawer = new Bundle();
bundledrawer.putSerializable("type", TimelineVM.TimelineType.HISTORY);
intent.putExtras(bundledrawer);
startActivity(intent);
} else if (item.getItemId() == R.id.action_most_liked) {
Intent intent = new Intent(PeertubeMainActivity.this, VideosTimelineActivity.class);
Bundle bundledrawer = new Bundle();
bundledrawer.putSerializable("type", TimelineVM.TimelineType.MOST_LIKED);
intent.putExtras(bundledrawer);
startActivity(intent);
} else if (item.getItemId() == R.id.action_playlist) {
Intent intent;
intent = new Intent(PeertubeMainActivity.this, AllPlaylistsActivity.class);
startActivity(intent);
} else if (item.getItemId() == R.id.action_sepia_search) {
Intent intent = new Intent(PeertubeMainActivity.this, SepiaSearchActivity.class);
startActivity(intent);
} else if (item.getItemId() == R.id.action_about) {
Intent intent = new Intent(PeertubeMainActivity.this, AboutActivity.class);
startActivity(intent);
}
binding.drawerLayout.close();
return false;
});
binding.drawerLayout.close();
return false;
});
} else {
binding.drawerNavView.setVisibility(View.GONE);
}
overviewFragment = new DisplayOverviewFragment();
if (!Helper.isLoggedIn()) {
@ -546,6 +578,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
case NORMAL:
accountItem.setVisible(true);
break;
case REMOTE_ACCOUNT:
case SURFING:
accountItem.setVisible(false);
break;
@ -601,7 +634,6 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
MenuItem incognitoItem = menu.findItem(R.id.action_incognito);
switch (typeOfConnection) {
case REMOTE_ACCOUNT:
case NORMAL:
if (Helper.isLoggedIn()) {
incognitoItem.setVisible(true);
@ -612,6 +644,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
incognitoItem.setVisible(false);
}
break;
case REMOTE_ACCOUNT:
case SURFING:
incognitoItem.setVisible(false);
break;

View file

@ -15,12 +15,18 @@ package app.fedilab.android.peertube.fragment;
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING;
import static app.fedilab.android.peertube.activities.PeertubeMainActivity.INSTANCE_ADDRESS;
import static app.fedilab.android.peertube.activities.PeertubeMainActivity.typeOfConnection;
import static app.fedilab.android.peertube.helper.Helper.peertubeInformation;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -34,6 +40,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -47,9 +54,12 @@ import java.util.Map;
import app.fedilab.android.R;
import app.fedilab.android.databinding.FragmentLoginPickInstancePeertubeBinding;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.peertube.activities.PeertubeMainActivity;
import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
import app.fedilab.android.peertube.client.data.InstanceData;
import app.fedilab.android.peertube.client.entities.InstanceParams;
import app.fedilab.android.peertube.client.entities.PeertubeInformation;
import app.fedilab.android.peertube.drawer.InstanceAdapter;
import app.fedilab.android.peertube.helper.RoundedBackgroundSpan;
import app.fedilab.android.peertube.viewmodel.InstancesVM;
@ -74,6 +84,36 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentLoginPickInstancePeertubeBinding.inflate(inflater, container, false);
if (peertubeInformation == null || peertubeInformation.getLanguages() == null) {
new Thread(() -> {
peertubeInformation = new PeertubeInformation();
peertubeInformation.setCategories(new LinkedHashMap<>());
peertubeInformation.setLanguages(new LinkedHashMap<>());
peertubeInformation.setLicences(new LinkedHashMap<>());
peertubeInformation.setPrivacies(new LinkedHashMap<>());
peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>());
peertubeInformation.setTranslations(new LinkedHashMap<>());
peertubeInformation = new RetrofitPeertubeAPI(requireActivity()).getPeertubeInformation();
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (peertubeInformation == null || peertubeInformation.getLanguages() == null) {
Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
} else {
initializeView();
}
};
mainHandler.post(myRunnable);
}).start();
} else {
initializeView();
}
return binding.getRoot();
}
private void initializeView() {
binding.loader.setVisibility(View.VISIBLE);
@ -100,7 +140,6 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta
}
});
if (peertubeInformation != null && peertubeInformation.getLanguages() != null) {
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
checkedItemsLanguage = new boolean[languages.size()];
@ -238,11 +277,9 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta
instanceParams = new InstanceParams();
instanceParams.setNsfwPolicy(channelSensitive[1]);
viewModel.getInstances(instanceParams).observe(getViewLifecycleOwner(), this::manageVIewInstance);
return binding.getRoot();
}
public void manageVIewInstance(APIResponse apiResponse) {
binding.loader.setVisibility(View.GONE);
if (apiResponse.getError() != null) {
@ -265,10 +302,20 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta
@Override
public void instance(String instance) {
Bundle bundle = new Bundle();
bundle.putString(INSTANCE_ADDRESS, instance);
Helper.addFragment(
getParentFragmentManager(), android.R.id.content, new PeertubeRegisterFragment(),
bundle, null, PeertubeRegisterFragment.class.getName());
if (typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, instance);
editor.commit();
Log.v(Helper.TAG, "-->: " + instance);
requireActivity().recreate();
} else {
Bundle bundle = new Bundle();
bundle.putString(INSTANCE_ADDRESS, instance);
Helper.addFragment(
getParentFragmentManager(), android.R.id.content, new PeertubeRegisterFragment(),
bundle, null, PeertubeRegisterFragment.class.getName());
}
}
}

View file

@ -14,13 +14,18 @@ package app.fedilab.android.peertube.helper;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentToken;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING;
import static app.fedilab.android.peertube.activities.PeertubeMainActivity.typeOfConnection;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import app.fedilab.android.peertube.activities.PeertubeMainActivity;
public class HelperInstance {
@ -33,7 +38,19 @@ public class HelperInstance {
*/
public static String getLiveInstance(Context context) {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedpreferences.getString(PREF_USER_INSTANCE, null);
if (typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) {
return sharedpreferences.getString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, null);
} else {
return sharedpreferences.getString(PREF_USER_INSTANCE, null);
}
}
public static String getToken() {
if (typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) {
return null;
} else {
return currentToken;
}
}
}

View file

@ -68,7 +68,10 @@
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="@dimen/fab_margin"
android:layout_marginStart="@dimen/fab_margin"
android:layout_marginTop="@dimen/fab_margin"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"
android:contentDescription="@string/instances_picker"
android:src="@drawable/ic_baseline_add_24"
android:tint="@android:color/white" />

View file

@ -18,6 +18,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/fab_margin"
android:background="?android:windowBackground">
<com.google.android.material.card.MaterialCardView
@ -42,6 +43,7 @@
android:gravity="center"
android:text="@string/pickup_categories"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/pickup_languages"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
@ -52,6 +54,7 @@
android:gravity="center"
android:text="@string/pickup_languages"
app:layout_constraintStart_toEndOf="@id/pickup_categories"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
@ -121,6 +124,7 @@
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"