代码优化

master
liuyx 2 years ago
parent 1c70e3bfa3
commit f3d8513083

@ -1,5 +1,6 @@
package cc.liuyx.note.activity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -21,6 +22,7 @@ import com.githang.statusbar.StatusBarCompat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Objects;
public abstract class BaseActivity extends AppCompatActivity {
@ -59,7 +61,6 @@ public abstract class BaseActivity extends AppCompatActivity {
public void setNightMode(){
if(isNightMode()) this.setTheme(R.style.NightTheme);
else setTheme(R.style.DayTheme);
}
protected abstract void needRefresh();
@ -71,8 +72,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}
public long calStrToSec(String date) throws ParseException {//decode calender date to second
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
long secTime = format.parse(date).getTime();
return secTime;
@SuppressLint("SimpleDateFormat") SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return Objects.requireNonNull(format.parse(date)).getTime();
}
}

@ -24,6 +24,7 @@ import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import cc.liuyx.note.db.NoteDatabase;
@ -47,7 +48,7 @@ public class EditActivity extends BaseActivity {
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
getSupportActionBar().setHomeButtonEnabled(true);
Objects.requireNonNull(getSupportActionBar()).setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

@ -481,8 +481,8 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
else myToolbar.setTitle("所有笔记");
}
@SuppressLint("InflateParams")
public void initPopupView() {
//instantiate the popup.xml layout file
layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
customView = (ViewGroup) layoutInflater.inflate(R.layout.setting_layout, null);
coverView = (ViewGroup) layoutInflater.inflate(R.layout.setting_cover, null);
@ -496,8 +496,6 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
}
private void initPrefs() {
//initialize all useful SharedPreferences for the first time the app runs
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor editor = sharedPreferences.edit();
if (!sharedPreferences.contains("nightMode")) {

@ -35,15 +35,12 @@ public class AlarmReceiver extends BroadcastReceiver {
manager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
.setContentTitle(title).setContentText(content).setSmallIcon(R.drawable.red_alarm_24dp)
.setContentIntent(pendingIntent).setAutoCancel(true).setFullScreenIntent(pendingIntent, true);
Notification notification = builder.build();
manager.notify(1, notification);
}
}

Loading…
Cancel
Save