mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Show edit button on ShowHabitFragment
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import org.isoron.helpers.ReplayableActivity;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -10,7 +11,7 @@ import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class ShowHabitActivity extends Activity
|
||||
public class ShowHabitActivity extends ReplayableActivity
|
||||
{
|
||||
|
||||
public Habit habit;
|
||||
@@ -33,18 +34,19 @@ public class ShowHabitActivity extends Activity
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.show_habit_menu, menu);
|
||||
getMenuInflater().inflate(R.menu.show_habit_activity_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
int id = item.getItemId();
|
||||
if(id == R.id.action_settings)
|
||||
switch(item.getItemId())
|
||||
{
|
||||
case R.id.action_settings:
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,19 @@ import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.isoron.helpers.ColorHelper;
|
||||
import org.isoron.helpers.Command;
|
||||
import org.isoron.helpers.DialogHelper;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.ReminderHelper;
|
||||
import org.isoron.uhabits.ShowHabitActivity;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.views.HabitHistoryView;
|
||||
@@ -19,9 +25,10 @@ import org.isoron.uhabits.views.HabitScoreView;
|
||||
import org.isoron.uhabits.views.HabitStreakView;
|
||||
import org.isoron.uhabits.views.RingView;
|
||||
|
||||
public class ShowHabitFragment extends Fragment
|
||||
public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedListener
|
||||
{
|
||||
protected ShowHabitActivity activity;
|
||||
private Habit habit;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
@@ -37,7 +44,7 @@ public class ShowHabitFragment extends Fragment
|
||||
|
||||
View view = inflater.inflate(R.layout.show_habit, container, false);
|
||||
activity = (ShowHabitActivity) getActivity();
|
||||
Habit habit = activity.habit;
|
||||
habit = activity.habit;
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21)
|
||||
{
|
||||
@@ -55,8 +62,8 @@ public class ShowHabitFragment extends Fragment
|
||||
tvStreaks.setTextColor(habit.color);
|
||||
|
||||
LinearLayout llOverview = (LinearLayout) view.findViewById(R.id.llOverview);
|
||||
llOverview.addView(new RingView(activity,
|
||||
(int) activity.getResources().getDimension(R.dimen.small_square_size) * 4, habit.color,
|
||||
llOverview.addView(new RingView(activity, (int) activity.getResources().getDimension(
|
||||
R.dimen.small_square_size) * 4, habit.color,
|
||||
((float) habit.getScore() / Habit.MAX_SCORE), "Habit strength"));
|
||||
|
||||
LinearLayout llStrength = (LinearLayout) view.findViewById(R.id.llStrength);
|
||||
@@ -73,6 +80,38 @@ public class ShowHabitFragment extends Fragment
|
||||
(int) activity.getResources().getDimension(R.dimen.small_square_size));
|
||||
llStreaks.addView(hsv);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
|
||||
{
|
||||
inflater.inflate(R.menu.show_habit_fragment_menu, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.action_edit_habit:
|
||||
{
|
||||
EditHabitFragment frag = EditHabitFragment.editSingleHabitFragment(habit.getId());
|
||||
frag.setOnSavedListener(this);
|
||||
frag.show(getFragmentManager(), "dialog");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaved(Command command)
|
||||
{
|
||||
activity.executeCommand(command);
|
||||
ReminderHelper.createReminderAlarms(activity);
|
||||
activity.recreate();
|
||||
}
|
||||
}
|
||||
|
||||
BIN
app/src/main/res/drawable-hdpi/ic_action_edit.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_action_edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 715 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_edit.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_action_edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 471 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_edit.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_action_edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 916 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_edit.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_action_edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
10
app/src/main/res/menu/show_habit_fragment_menu.xml
Normal file
10
app/src/main/res/menu/show_habit_fragment_menu.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_edit_habit"
|
||||
android:showAsAction="ifRoom"
|
||||
android:icon="@drawable/ic_action_edit"
|
||||
android:title="@string/edit"/>
|
||||
|
||||
</menu>
|
||||
Reference in New Issue
Block a user