mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Remove dead code
This commit is contained in:
@@ -1,91 +1,31 @@
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.isoron.helpers.ReplayableActivity;
|
||||
import org.isoron.helpers.Command;
|
||||
import org.isoron.helpers.ReplayableActivity;
|
||||
import org.isoron.uhabits.dialogs.ListHabitsFragment;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class MainActivity extends ReplayableActivity
|
||||
implements ListHabitsFragment.OnHabitClickListener
|
||||
{
|
||||
private ListHabitsFragment listHabitsFragment;
|
||||
|
||||
public static void createReminderAlarms(Context context)
|
||||
{
|
||||
for (Habit habit : Habit.getHabitsWithReminder())
|
||||
createReminderAlarm(context, habit, null);
|
||||
}
|
||||
|
||||
public static void createReminderAlarm(Context context, Habit habit, Long reminderTime)
|
||||
{
|
||||
Uri uri = Uri.parse("content://org.isoron.uhabits/habit/" + habit.getId());
|
||||
|
||||
if (reminderTime == null)
|
||||
{
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
calendar.set(Calendar.HOUR_OF_DAY, habit.reminder_hour);
|
||||
calendar.set(Calendar.MINUTE, habit.reminder_min);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
|
||||
reminderTime = calendar.getTimeInMillis();
|
||||
|
||||
if (System.currentTimeMillis() > reminderTime)
|
||||
{
|
||||
reminderTime += AlarmManager.INTERVAL_DAY;
|
||||
}
|
||||
}
|
||||
|
||||
Intent alarmIntent = new Intent(context, ReminderAlarmReceiver.class);
|
||||
alarmIntent.setAction(ReminderAlarmReceiver.ACTION_REMIND);
|
||||
alarmIntent.setData(uri);
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
|
||||
((int) (habit.getId() % Integer.MAX_VALUE)) + 1, alarmIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= 19)
|
||||
{
|
||||
manager.setExact(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
|
||||
}
|
||||
else
|
||||
{
|
||||
manager.set(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
|
||||
}
|
||||
|
||||
Log.d("Alarm", String.format("Setting alarm (%s): %s",
|
||||
DateFormat.getDateTimeInstance().format(new Date(reminderTime)), habit.name));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21) getActionBar().setElevation(5);
|
||||
|
||||
setContentView(R.layout.list_habits_activity);
|
||||
|
||||
listHabitsFragment = (ListHabitsFragment) getFragmentManager().findFragmentById(
|
||||
R.id.fragment1);
|
||||
|
||||
createReminderAlarms(MainActivity.this);
|
||||
ReminderHelper.createReminderAlarms(MainActivity.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,13 +47,11 @@ public class MainActivity extends ReplayableActivity
|
||||
{
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_settings)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onHabitClicked(Habit habit)
|
||||
{
|
||||
@@ -122,10 +60,10 @@ public class MainActivity extends ReplayableActivity
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCommandExecuted(Command command)
|
||||
public void executeCommand(Command command)
|
||||
{
|
||||
super.executeCommand(command);
|
||||
listHabitsFragment.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,6 @@ public class ListHabitsFragment extends Fragment
|
||||
tvNameWidth = (int) ((width - 30 - button_count * 42) * dm.density);
|
||||
|
||||
tvNameHeader = (TextView) view.findViewById(R.id.tvNameHeader);
|
||||
// updateStarCount();
|
||||
|
||||
adapter = new ListHabitsAdapter(getActivity());
|
||||
listView = (DragSortListView) view.findViewById(R.id.listView);
|
||||
@@ -272,17 +271,6 @@ public class ListHabitsFragment extends Fragment
|
||||
{
|
||||
}
|
||||
|
||||
void updateStarCount()
|
||||
{
|
||||
String msg = "";
|
||||
int starCount = Habit.getStarCount();
|
||||
|
||||
if (starCount == 1) msg = String.format("%d star", starCount);
|
||||
else if (starCount > 1) msg = String.format("%d stars", starCount);
|
||||
|
||||
tvNameHeader.setText(msg);
|
||||
}
|
||||
|
||||
class ListHabitsAdapter extends BaseAdapter
|
||||
{
|
||||
private Context context;
|
||||
@@ -328,37 +316,28 @@ public class ListHabitsFragment extends Fragment
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(tvNameWidth,
|
||||
LayoutParams.WRAP_CONTENT, 1);
|
||||
((TextView) view.findViewById(R.id.tvName)).setLayoutParams(params);
|
||||
view.findViewById(R.id.tvName).setLayoutParams(params);
|
||||
|
||||
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
|
||||
.getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
display.getSize(size);
|
||||
|
||||
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
llp.setMargins(2, 0, 2, 0);
|
||||
|
||||
for (int i = 0; i < button_count; i++)
|
||||
{
|
||||
View check = inflater.inflate(R.layout.list_habits_item_check, null);
|
||||
TextView btCheck = (TextView) check.findViewById(R.id.tvCheck);
|
||||
btCheck.setTypeface(fontawesome);
|
||||
btCheck.setOnLongClickListener(ListHabitsFragment.this);
|
||||
// btCheck.setLayoutParams(llp);
|
||||
((LinearLayout) view.findViewById(R.id.llButtons)).addView(check);
|
||||
}
|
||||
|
||||
// LinearLayout llInner = (LinearLayout) view.findViewById(R.id.llInner);
|
||||
// llInner.setOnClickListener(ListHabitsFragment.this);
|
||||
|
||||
view.setTag(R.id.KEY_TIMESTAMP, DateHelper.getStartOfToday());
|
||||
}
|
||||
|
||||
TextView tvStar = (TextView) view.findViewById(R.id.tvStar);
|
||||
TextView tvName = (TextView) view.findViewById(R.id.tvName);
|
||||
|
||||
|
||||
if (habit == null)
|
||||
{
|
||||
tvName.setText(null);
|
||||
|
||||
Reference in New Issue
Block a user