Multi account
|
@ -236,4 +236,6 @@
|
|||
<string name="no_opinion">No opinion</string>
|
||||
<string name="pickup_languages">Pickup languages</string>
|
||||
<string name="notification_channel_name">Mise à jour des informations</string>
|
||||
|
||||
<string name="list_of_accounts">Liste des comptes</string>
|
||||
</resources>
|
||||
|
|
|
@ -252,4 +252,7 @@
|
|||
<string name="pickup_categories">Pickup categories</string>
|
||||
<string name="pickup_languages">Pickup languages</string>
|
||||
<string name="notification_channel_name">Update information</string>
|
||||
|
||||
<string name="add_account">Add an account</string>
|
||||
<string name="list_of_accounts">List of accounts</string>
|
||||
</resources>
|
|
@ -5,15 +5,15 @@
|
|||
|
||||
|
||||
<!--
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
<application
|
||||
android:name=".FedilabTube"
|
||||
|
|
|
@ -100,7 +100,7 @@ public class AboutActivity extends AppCompatActivity {
|
|||
});
|
||||
|
||||
LinearLayout donation_container = findViewById(R.id.donation_container);
|
||||
if (BuildConfig.google_restriction) {
|
||||
if (BuildConfig.google_restriction || !BuildConfig.full_instances) {
|
||||
donation_container.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.text.SpannableString;
|
|||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.UnderlineSpan;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
|
@ -40,7 +41,10 @@ import com.google.android.material.tabs.TabLayout;
|
|||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.drawer.OwnAccountsAdapter;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayNotificationsFragment;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
@ -194,12 +198,50 @@ public class AccountActivity extends AppCompatActivity {
|
|||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main_profile, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_add_account) {
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<Account> accounts = new AccountDAO(AccountActivity.this, db).getAllAccount();
|
||||
|
||||
AlertDialog.Builder builderSingle = new AlertDialog.Builder(AccountActivity.this);
|
||||
builderSingle.setTitle(getString(R.string.list_of_accounts));
|
||||
final OwnAccountsAdapter accountsListAdapter = new OwnAccountsAdapter(AccountActivity.this, accounts);
|
||||
final Account[] accountArray = new Account[accounts.size()];
|
||||
int i = 0;
|
||||
for (Account account : accounts) {
|
||||
accountArray[i] = account;
|
||||
i++;
|
||||
}
|
||||
builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
builderSingle.setPositiveButton(R.string.add_account, (dialog, which) -> {
|
||||
Intent intent = new Intent(AccountActivity.this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
});
|
||||
builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> {
|
||||
final Account account = accountArray[which];
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
|
||||
editor.putString(Helper.PREF_INSTANCE, account.getInstance());
|
||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||
editor.apply();
|
||||
dialog.dismiss();
|
||||
Intent intent = new Intent(AccountActivity.this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
});
|
||||
builderSingle.show();
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
@ -83,6 +83,9 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
|
|||
if (BuildConfig.full_instances) {
|
||||
login_instance_container.setVisibility(View.VISIBLE);
|
||||
title_login_instance.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
login_instance_container.setVisibility(View.GONE);
|
||||
title_login_instance.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
username.setOnFocusChangeListener((view, focused) -> {
|
||||
|
@ -161,7 +164,11 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
|
|||
signup.setEnabled(false);
|
||||
|
||||
if (BuildConfig.full_instances) {
|
||||
instance = login_instance.getText().toString();
|
||||
if (login_instance.getText() != null) {
|
||||
instance = login_instance.getText().toString();
|
||||
} else {
|
||||
instance = "";
|
||||
}
|
||||
} else {
|
||||
String host = emailArray[1];
|
||||
instance = Helper.getPeertubeUrl(host);
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
package app.fedilab.fedilabtube.drawer;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
||||
|
||||
public class OwnAccountsAdapter extends ArrayAdapter<Account> {
|
||||
|
||||
private List<Account> accounts;
|
||||
private LayoutInflater layoutInflater;
|
||||
|
||||
public OwnAccountsAdapter(Context context, List<Account> accounts) {
|
||||
super(context, android.R.layout.simple_list_item_1, accounts);
|
||||
this.accounts = accounts;
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return accounts.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account getItem(int position) {
|
||||
return accounts.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
|
||||
|
||||
final Account account = accounts.get(position);
|
||||
final ViewHolder holder;
|
||||
if (convertView == null) {
|
||||
convertView = layoutInflater.inflate(R.layout.drawer_account_owner, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.account_pp = convertView.findViewById(R.id.account_pp);
|
||||
holder.account_un = convertView.findViewById(R.id.account_un);
|
||||
|
||||
holder.account_container = convertView.findViewById(R.id.account_container);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
holder.account_un.setText(String.format("@%s", account.getAcct()));
|
||||
//Profile picture
|
||||
Helper.loadGiF(holder.account_pp.getContext(), account.getAvatar().compareTo("null") != 0 ? "https://" + account.getInstance() + account.getAvatar() : "null", holder.account_pp);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
private static class ViewHolder {
|
||||
ImageView account_pp;
|
||||
TextView account_un;
|
||||
LinearLayout account_container;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -57,6 +57,7 @@ import java.util.TimeZone;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import app.fedilab.fedilabtube.BuildConfig;
|
||||
import app.fedilab.fedilabtube.LoginActivity;
|
||||
import app.fedilab.fedilabtube.MainActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.WebviewActivity;
|
||||
|
@ -627,29 +628,38 @@ public class Helper {
|
|||
* Log out the authenticated user by removing its token
|
||||
*
|
||||
* @param activity Activity
|
||||
* @param account Account
|
||||
*/
|
||||
public static void logoutCurrentUser(Activity activity, Account account) {
|
||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
|
||||
//Current user
|
||||
SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
|
||||
if (account != null) {
|
||||
new AccountDAO(activity, db).removeUser(account);
|
||||
}
|
||||
Account newAccount = new AccountDAO(activity, db).getLastUsedAccount();
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
editor.putString(Helper.CLIENT_ID, null);
|
||||
editor.putString(Helper.CLIENT_SECRET, null);
|
||||
editor.putString(Helper.PREF_KEY_ID, null);
|
||||
editor.putBoolean(Helper.PREF_IS_MODERATOR, false);
|
||||
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, false);
|
||||
editor.putString(Helper.PREF_INSTANCE, null);
|
||||
editor.putString(Helper.ID, null);
|
||||
editor.apply();
|
||||
Intent mainActivity = new Intent(activity, MainActivity.class);
|
||||
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.ADD_USER_INTENT);
|
||||
activity.startActivity(mainActivity);
|
||||
activity.finish();
|
||||
|
||||
if (newAccount == null) {
|
||||
editor.putString(PREF_KEY_OAUTH_TOKEN, null);
|
||||
editor.putString(CLIENT_ID, null);
|
||||
editor.putString(CLIENT_SECRET, null);
|
||||
editor.putString(PREF_KEY_ID, null);
|
||||
editor.putString(PREF_INSTANCE, null);
|
||||
editor.putString(ID, null);
|
||||
editor.apply();
|
||||
Intent loginActivity = new Intent(activity, LoginActivity.class);
|
||||
activity.startActivity(loginActivity);
|
||||
activity.finish();
|
||||
} else {
|
||||
editor.putString(PREF_KEY_OAUTH_TOKEN, newAccount.getToken());
|
||||
editor.putString(PREF_KEY_ID, newAccount.getId());
|
||||
editor.putString(PREF_INSTANCE, newAccount.getInstance().trim());
|
||||
editor.commit();
|
||||
Intent changeAccount = new Intent(activity, MainActivity.class);
|
||||
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
activity.startActivity(changeAccount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,10 @@ package app.fedilab.fedilabtube.services;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
|
@ -25,6 +28,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.HttpsConnection;
|
||||
|
@ -37,7 +41,7 @@ import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
|||
|
||||
public class RetrieveInfoService extends Service implements NetworkStateReceiver.NetworkStateReceiverListener {
|
||||
|
||||
static String NOTIFICATION_CHANNEL_ID = "update_info";
|
||||
static String NOTIFICATION_CHANNEL_ID = "update_info_peertube";
|
||||
private NetworkStateReceiver networkStateReceiver;
|
||||
|
||||
|
||||
|
@ -53,19 +57,26 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
|
|||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Notification.Builder builder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
|
||||
getString(R.string.notification_channel_name),
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
channel.setSound(null, null);
|
||||
|
||||
((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel);
|
||||
android.app.Notification notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_notification_tubelab)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.notification_channel_name))
|
||||
.setAutoCancel(true);
|
||||
.setAutoCancel(true).build();
|
||||
|
||||
Notification notification = builder.build();
|
||||
startForeground(1, notification);
|
||||
|
||||
} else {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setDefaults(Notification.DEFAULT_ALL)
|
||||
.setContentText(getString(R.string.notification_channel_name))
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
.setAutoCancel(true);
|
||||
|
|
|
@ -73,6 +73,7 @@ public class AccountsVM extends AndroidViewModel {
|
|||
CHANNEL,
|
||||
MUTED,
|
||||
SINGLE_ACCOUNT,
|
||||
SINGLE_CHANNEL
|
||||
SINGLE_CHANNEL,
|
||||
OWN_ACCOUNTS
|
||||
}
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 499 B After Width: | Height: | Size: 720 B |
Before Width: | Height: | Size: 359 B After Width: | Height: | Size: 491 B |
Before Width: | Height: | Size: 614 B After Width: | Height: | Size: 937 B |
Before Width: | Height: | Size: 905 B After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.6 KiB |
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z" />
|
||||
</vector>
|
|
@ -85,7 +85,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/title_instance_login"
|
||||
android:inputType="textWebEditText"
|
||||
android:inputType="textWebEmailAddress"
|
||||
android:singleLine="true" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Copyright 2020 Thomas Schneider
|
||||
|
||||
This file is a part of TubeLab
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/account_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="5dp"
|
||||
tools:ignore="UseCompoundDrawables">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/account_pp"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/profile_picture" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_un"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_add_account"
|
||||
android:icon="@drawable/ic_baseline_person_add_24"
|
||||
android:title="@string/add_account"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|