Skip to content

Commit

Permalink
修复任务switch组件的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
tignioj committed Jun 12, 2020
1 parent 119d317 commit d01b7e2
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .idea/sqlandroid.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ public FreezeTasker getFreezeTaskerById(long id) {

public void updateFreezeTasks(FreezeTasker... freezeTaskerFromDb) {
freezeTaskerRepository.insertFreezeTasker(freezeTaskerFromDb);

}


public LiveData<List<AppsCategory>> findAppCategorysLiveWithPattern(String pattern) {
return appsCategoryRepository.findAppCategorysLiveWithPattern(pattern);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ScreenReceiver extends BroadcastReceiver {

public static void lockNow(Context context) {
Log.d(MyConfig.LOG_TAG_FREEZE_SERVICE, "lock_now");
DeviceMethod.getInstance(context).lockNow();
// DeviceMethod.getInstance(context).lockNow();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public synchronized void onChanged(ConcurrentHashMap<String, String> strings) {
builder.setContentText(content.toString());
if (start != null) {
builder.setContentTitle(start + "-" + end);
} else {
builder.setContentTitle(null);
}
startForeground(NOTIFICATION_ID, builder.build());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tignioj.freezeapp.ui.home.applist;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TimePicker;
import android.widget.Toast;

Expand Down Expand Up @@ -50,6 +52,7 @@ public class FreezeTimerEditFragment extends Fragment {
private RadioButton radioButtonFreeze, radioButtonUnFreeze;
private CheckBox checkBoxEditTimerIsLockScreen;
private EditText editTextDescription;
private Switch switchEnableSIngleTask;

private HomeViewModel homeViewModel;

Expand Down Expand Up @@ -135,6 +138,11 @@ public void onClick(View v) {
}
});

switchEnableSIngleTask = inflate.findViewById(R.id.switchEnableSIngleTask);
switchEnableSIngleTask.setChecked(freezeTaskerFromDb.isEnable());



radioGroupUnFreezeOrUnfreeze = inflate.findViewById(R.id.radioButtonUnFreezeOrUnfreeze);
radioButtonFreeze = inflate.findViewById(R.id.radioButtonFreeze);
radioButtonUnFreeze = inflate.findViewById(R.id.radioButtonUnfreeze);
Expand Down Expand Up @@ -185,6 +193,9 @@ public void onClick(View v) {
}

freezeTaskerFromDb.setLockScreen(checkBoxEditTimerIsLockScreen.isChecked());

freezeTaskerFromDb.setEnable(switchEnableSIngleTask.isChecked());

// homeViewModel.insertFreezeTasks(freezeTaskerFromDb);
homeViewModel.updateFreezeTasks(freezeTaskerFromDb);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.tignioj.freezeapp.utils.MyDateUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class TimerAdapter extends ListAdapter<FreezeTasker, TimerAdapter.MyViewHolder> {

Expand Down Expand Up @@ -77,7 +78,7 @@ public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)

@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {
FreezeTasker item = getItem(position);
final FreezeTasker item = getItem(position);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String formatStart = sdf.format(item.getStartTime());

Expand Down Expand Up @@ -110,12 +111,18 @@ public void onBindViewHolder(@NonNull final MyViewHolder holder, final int posit
// });
holder.aSwitchEnable.setChecked(item.isEnable());



holder.aSwitchEnable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
final FreezeTasker currentDeleteItem = getItem(position);
currentDeleteItem.setEnable(isChecked);
timerFragment.homeViewModel.updateFreezeTasks(currentDeleteItem);
FreezeTasker item1 = getItem(holder.getAdapterPosition());
Log.d("switchChange1", item1.getDescription());
if (item1.isEnable() != isChecked) {
item1.setEnable(isChecked);
timerFragment.homeViewModel.updateFreezeTasks(item1);
}

}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ public void onClick(View v) {



final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
boolean enableAll = mPrefs.getBoolean(MyConfig.PERSONAL_SHP_CONFIG_KEY_ENABLE_ALL_TASKS, true);
aSwitchEnableAll = inflate.findViewById(R.id.switch_eanble_all_task);
aSwitchEnableAll.setChecked(enableAll);


aSwitchEnableAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
homeViewModel.updateFreezeTasksAllEnable(isChecked);
SharedPreferences.Editor edit = mPrefs.edit();
edit.putBoolean(MyConfig.PERSONAL_SHP_CONFIG_KEY_ENABLE_ALL_TASKS, isChecked);
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fragment_edit_timer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,15 @@
app:layout_constraintStart_toEndOf="@+id/button_addTimer_Back"
app:layout_constraintTop_toTopOf="@+id/button_addTimer_Back" />

<Switch
android:id="@+id/switchEnableSIngleTask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/enable"
app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintEnd_toStartOf="@+id/guideline6"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/textView" />


</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit d01b7e2

Please sign in to comment.