Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exit option for issue #170 #171

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Last Launcher
* Copyright (C) 2022 LIU Tong
*
* 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/

package io.github.subhamtyagi.lastlauncher.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;

import io.github.subhamtyagi.lastlauncher.LauncherActivity;
import io.github.subhamtyagi.lastlauncher.R;

public class ExitDialog extends Dialog implements View.OnClickListener{

private final LauncherActivity context;

ExitDialog(Context context, LauncherActivity launcherActivity) {
super(context);
this.context = launcherActivity;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_exit);
LinearLayout ll = findViewById(R.id.exit_layout);
for (int i = 0; i < ll.getChildCount(); i++) {
ll.getChildAt(i).setOnClickListener(this);
}
}

@Override
public void onClick(View view) {
if (view.getId() == R.id.t1) {
shutdown();
}
if (view.getId() == R.id.t2) {
rollBack();
}
}

private void shutdown() {
System.exit(0);
}

private void rollBack() {
cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.settings_color_size).setOnClickListener(this);
findViewById(R.id.settings_sort_app_by).setOnClickListener(this);
findViewById(R.id.settings_restart_launcher).setOnClickListener(this);
findViewById(R.id.settings_exit).setOnClickListener(this);

//TODO: remove this var
TextView colorSniffer = findViewById(R.id.settings_color_sniffer);
Expand Down Expand Up @@ -165,6 +166,10 @@ public void onClick(View view) {
case R.id.settings_restart_launcher:
launcherActivity.recreate();
break;
// same as upper code, when click it show exit confirm dialog
case R.id.settings_exit:
showExitDialog();
break;

}
}
Expand Down Expand Up @@ -313,6 +318,14 @@ private void showThemeDialog() {
new ThemeSelectorDialog(getContext(), launcherActivity).show();
}

/**
* show the exit confirm dialog
*/
private void showExitDialog() {
cancel();
new ExitDialog(getContext(), launcherActivity).show();
}

private void defaultSettings() {
if (!BuildConfig.DEBUG) {
DbUtils.clearDB();
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/layout/dialog_exit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/exit_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/t1"
style="@style/Hacker.red"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:tag="AppTheme"
android:text="@android:string/yes"
android:textSize="22sp" />

<TextView
android:id="@+id/t2"
style="@style/Hacker.green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:tag="AppTheme"
android:text="@android:string/cancel"
android:textSize="22sp" />
</LinearLayout>
19 changes: 19 additions & 0 deletions app/src/main/res/layout/dialog_global_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,25 @@
android:text="@string/restart_launcher"
android:textSize="20sp" />

<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center|center_horizontal|center_vertical"
android:background="#DEDEDE"
android:foregroundGravity="center_vertical|center_horizontal" />

<TextView
android:id="@+id/settings_exit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="5dp"

android:paddingBottom="5dp"
android:text="@string/end"
android:textSize="20sp" />


</LinearLayout>
</ScrollView>
1 change: 0 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<item name="android:listPreferredItemHeightSmall">40dp</item>
<item name="android:listPreferredItemPaddingLeft">5dp</item>
<item name="android:listPreferredItemPaddingRight">5dp</item>
<item name="android:textColor">#FFFFFFFF</item>
<!--<item name="android:switchTextAppearance">#FFFFff</item>-->
<item name="android:popupBackground">#FF000000</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
Expand Down