feat(compose-shortcut): allow user to choose account
This commit is contained in:
@@ -81,6 +81,15 @@
|
|||||||
<data android:mimeType="*/*"/>
|
<data android:mimeType="*/*"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity android:name=".ChooseAccountForComposeActivity" android:exported="true" android:configChanges="orientation|screenSize" android:windowSoftInputMode="adjustResize"
|
||||||
|
android:theme="@style/TransparentDialog">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.CHOOSER"/>
|
||||||
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
<data android:mimeType="*/*"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
|
||||||
<service android:name=".AudioPlayerService" android:foregroundServiceType="mediaPlayback"/>
|
<service android:name=".AudioPlayerService" android:foregroundServiceType="mediaPlayback"/>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package org.joinmastodon.android;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.session.AccountSession;
|
||||||
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
|
import org.joinmastodon.android.fragments.ComposeFragment;
|
||||||
|
import org.joinmastodon.android.ui.sheets.AccountSwitcherSheet;
|
||||||
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import me.grishka.appkit.FragmentStackActivity;
|
||||||
|
|
||||||
|
public class ChooseAccountForComposeActivity extends FragmentStackActivity{
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState){
|
||||||
|
UiUtils.setUserPreferredTheme(this);
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (savedInstanceState == null && Objects.equals(getIntent().getAction(), Intent.ACTION_CHOOSER)) {
|
||||||
|
AccountSessionManager.getInstance().maybeUpdateLocalInfo();
|
||||||
|
List<AccountSession> sessions=AccountSessionManager.getInstance().getLoggedInAccounts();
|
||||||
|
if (sessions.isEmpty()){
|
||||||
|
Toast.makeText(this, R.string.err_not_logged_in, Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
} else if (sessions.size() > 1) {
|
||||||
|
AccountSwitcherSheet sheet = new AccountSwitcherSheet(this, null, R.drawable.ic_fluent_compose_28_regular,
|
||||||
|
R.string.choose_account, null, false);
|
||||||
|
sheet.setOnClick((accountId, open) -> {
|
||||||
|
openComposeFragment(accountId);
|
||||||
|
});
|
||||||
|
sheet.show();
|
||||||
|
} else if (sessions.size() == 1) {
|
||||||
|
openComposeFragment(sessions.get(0).getID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openComposeFragment(String accountID){
|
||||||
|
getWindow().setBackgroundDrawable(null);
|
||||||
|
Bundle args=new Bundle();
|
||||||
|
args.putString("account", accountID);
|
||||||
|
Fragment fragment=new ComposeFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
showFragmentClearingBackStack(fragment);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -111,8 +111,6 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
|
|||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
showFragmentClearingBackStack(fragment);
|
showFragmentClearingBackStack(fragment);
|
||||||
}
|
}
|
||||||
}else if(intent.getBooleanExtra("compose", false)){
|
|
||||||
showCompose();
|
|
||||||
}else if(Intent.ACTION_VIEW.equals(intent.getAction())){
|
}else if(Intent.ACTION_VIEW.equals(intent.getAction())){
|
||||||
handleURL(intent.getData(), null);
|
handleURL(intent.getData(), null);
|
||||||
}/*else if(intent.hasExtra(PackageInstaller.EXTRA_STATUS) && GithubSelfUpdater.needSelfUpdating()){
|
}/*else if(intent.hasExtra(PackageInstaller.EXTRA_STATUS) && GithubSelfUpdater.needSelfUpdating()){
|
||||||
@@ -187,17 +185,6 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
|
|||||||
showFragment(fragment);
|
showFragment(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showCompose(){
|
|
||||||
AccountSession session=AccountSessionManager.getInstance().getLastActiveAccount();
|
|
||||||
if(session==null || !session.activated)
|
|
||||||
return;
|
|
||||||
ComposeFragment compose=new ComposeFragment();
|
|
||||||
Bundle composeArgs=new Bundle();
|
|
||||||
composeArgs.putString("account", session.getID());
|
|
||||||
compose.setArguments(composeArgs);
|
|
||||||
showFragment(compose);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void maybeRequestNotificationsPermission(){
|
private void maybeRequestNotificationsPermission(){
|
||||||
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)!=PackageManager.PERMISSION_GRANTED){
|
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)!=PackageManager.PERMISSION_GRANTED){
|
||||||
requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, 100);
|
requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, 100);
|
||||||
@@ -343,8 +330,6 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
|
|||||||
}catch(BadParcelableException x){
|
}catch(BadParcelableException x){
|
||||||
Log.w(TAG, x);
|
Log.w(TAG, x);
|
||||||
}
|
}
|
||||||
} else if (intent.getBooleanExtra("compose", false)){
|
|
||||||
showCompose();
|
|
||||||
} else if (Intent.ACTION_VIEW.equals(intent.getAction())){
|
} else if (Intent.ACTION_VIEW.equals(intent.getAction())){
|
||||||
handleURL(intent.getData(), null);
|
handleURL(intent.getData(), null);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.joinmastodon.android.api.session;
|
package org.joinmastodon.android.api.session;
|
||||||
|
|
||||||
import static org.unifiedpush.android.connector.UnifiedPush.getDistributor;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
@@ -17,8 +15,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.joinmastodon.android.BuildConfig;
|
import org.joinmastodon.android.BuildConfig;
|
||||||
import org.joinmastodon.android.E;
|
import org.joinmastodon.android.E;
|
||||||
import org.joinmastodon.android.GlobalUserPreferences;
|
import org.joinmastodon.android.ChooseAccountForComposeActivity;
|
||||||
import org.joinmastodon.android.MainActivity;
|
|
||||||
import org.joinmastodon.android.MastodonApp;
|
import org.joinmastodon.android.MastodonApp;
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
import org.joinmastodon.android.api.MastodonAPIController;
|
import org.joinmastodon.android.api.MastodonAPIController;
|
||||||
@@ -494,12 +491,11 @@ public class AccountSessionManager{
|
|||||||
if((sm.getDynamicShortcuts().isEmpty() || BuildConfig.DEBUG) && !sessions.isEmpty()){
|
if((sm.getDynamicShortcuts().isEmpty() || BuildConfig.DEBUG) && !sessions.isEmpty()){
|
||||||
// There are no shortcuts, but there are accounts. Add a compose shortcut.
|
// There are no shortcuts, but there are accounts. Add a compose shortcut.
|
||||||
ShortcutInfo info=new ShortcutInfo.Builder(MastodonApp.context, "compose")
|
ShortcutInfo info=new ShortcutInfo.Builder(MastodonApp.context, "compose")
|
||||||
.setActivity(ComponentName.createRelative(MastodonApp.context, MainActivity.class.getName()))
|
.setActivity(ComponentName.createRelative(MastodonApp.context, ChooseAccountForComposeActivity.class.getName()))
|
||||||
.setShortLabel(MastodonApp.context.getString(R.string.new_post))
|
.setShortLabel(MastodonApp.context.getString(R.string.new_post))
|
||||||
.setIcon(Icon.createWithResource(MastodonApp.context, R.mipmap.ic_shortcut_compose))
|
.setIcon(Icon.createWithResource(MastodonApp.context, R.mipmap.ic_shortcut_compose))
|
||||||
.setIntent(new Intent(MastodonApp.context, MainActivity.class)
|
.setIntent(new Intent(MastodonApp.context, ChooseAccountForComposeActivity.class)
|
||||||
.setAction(Intent.ACTION_MAIN)
|
.setAction(Intent.ACTION_CHOOSER))
|
||||||
.putExtra("compose", true))
|
|
||||||
.build();
|
.build();
|
||||||
sm.setDynamicShortcuts(Collections.singletonList(info));
|
sm.setDynamicShortcuts(Collections.singletonList(info));
|
||||||
}else if(sessions.isEmpty()){
|
}else if(sessions.isEmpty()){
|
||||||
|
|||||||
Reference in New Issue
Block a user