-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AppInfo] Add “New profile” option in the “Add to profile” dialog
Signed-off-by: Muntashir Al-Islam <[email protected]>
- Loading branch information
1 parent
39499c4
commit 2f4da4c
Showing
5 changed files
with
101 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...src/main/java/io/github/muntashirakon/AppManager/profiles/AddToProfileDialogFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package io.github.muntashirakon.AppManager.profiles; | ||
|
||
import static io.github.muntashirakon.AppManager.utils.UIUtils.getSecondaryText; | ||
import static io.github.muntashirakon.AppManager.utils.UIUtils.getSmallerText; | ||
|
||
import android.app.Dialog; | ||
import android.os.Bundle; | ||
import android.text.SpannableStringBuilder; | ||
import android.text.TextUtils; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AlertDialog; | ||
import androidx.fragment.app.DialogFragment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import io.github.muntashirakon.AppManager.R; | ||
import io.github.muntashirakon.AppManager.utils.UIUtils; | ||
import io.github.muntashirakon.dialog.DialogTitleBuilder; | ||
import io.github.muntashirakon.dialog.SearchableMultiChoiceDialogBuilder; | ||
import io.github.muntashirakon.dialog.TextInputDialogBuilder; | ||
|
||
public class AddToProfileDialogFragment extends DialogFragment { | ||
public static final String TAG = AddToProfileDialogFragment.class.getSimpleName(); | ||
|
||
private static final String ARG_PKGS = "pkgs"; | ||
|
||
public static AddToProfileDialogFragment getInstance(@NonNull String[] packages) { | ||
AddToProfileDialogFragment fragment = new AddToProfileDialogFragment(); | ||
Bundle args = new Bundle(); | ||
args.putStringArray(ARG_PKGS, packages); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | ||
String[] packages = requireArguments().getStringArray(ARG_PKGS); | ||
List<ProfileMetaManager> profiles = ProfileManager.getProfileMetadata(); | ||
List<CharSequence> profileNames = new ArrayList<>(profiles.size()); | ||
for (ProfileMetaManager profileMetaManager : profiles) { | ||
profileNames.add(new SpannableStringBuilder(profileMetaManager.getProfileName()).append("\n") | ||
.append(getSecondaryText(requireContext(), getSmallerText(profileMetaManager | ||
.toLocalizedString(requireContext()))))); | ||
} | ||
AtomicReference<AlertDialog> dialogRef = new AtomicReference<>(); | ||
DialogTitleBuilder titleBuilder = new DialogTitleBuilder(requireContext()) | ||
.setTitle(R.string.add_to_profile) | ||
.setEndIconContentDescription(R.string.new_profile) | ||
.setEndIcon(R.drawable.ic_add, v -> new TextInputDialogBuilder(requireContext(), R.string.input_profile_name) | ||
.setTitle(R.string.new_profile) | ||
.setHelperText(R.string.input_profile_name_description) | ||
.setNegativeButton(R.string.cancel, null) | ||
.setPositiveButton(R.string.go, (dialog, which, profName, isChecked) -> { | ||
if (!TextUtils.isEmpty(profName)) { | ||
//noinspection ConstantConditions | ||
startActivity(AppsProfileActivity.getNewProfileIntent(requireContext(), profName.toString(), | ||
packages)); | ||
if (dialogRef.get() != null) { | ||
dialogRef.get().dismiss(); | ||
} | ||
} | ||
}) | ||
.show()); | ||
AlertDialog alertDialog = new SearchableMultiChoiceDialogBuilder<>(requireContext(), profiles, profileNames) | ||
.setTitle(titleBuilder.build()) | ||
.setNegativeButton(R.string.cancel, null) | ||
.setPositiveButton(R.string.add, (dialog, which, selectedItems) -> { | ||
for (ProfileMetaManager metaManager : selectedItems) { | ||
try { | ||
metaManager.appendPackages(packages); | ||
metaManager.writeProfile(); | ||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
UIUtils.displayShortToast(R.string.done); | ||
}) | ||
.create(); | ||
dialogRef.set(alertDialog); | ||
return alertDialog; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters