Skip to content

Commit

Permalink
added AppWidget with Listview and the ability to swipe between recipe…
Browse files Browse the repository at this point in the history
…s ingrediants - fixed on fragment detail view onSwipe function - created a content provider (no use for it yet)
  • Loading branch information
medyas committed Oct 14, 2018
1 parent 84eabaa commit 7485241
Show file tree
Hide file tree
Showing 22 changed files with 422 additions and 36 deletions.
5 changes: 3 additions & 2 deletions .idea/assetWizardSettings.xml

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

Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,38 @@
android:name=".Activities.RecipeDetailViewActivity"
android:parentActivityName=".Activities.RecipeDetailActivity" />
<activity android:name=".Activities.SettingsActivity" />

<activity android:name=".Activities.AboutActivity" />

<receiver android:name=".Widget.RecipesWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<intent-filter>
<action android:name="ACTION_UPDATE_SHOW_PREV"/>
</intent-filter>

<intent-filter>
<action android:name="ACTION_UPDATE_SHOW_NEXT"/>
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/recipes_widget_info" />
</receiver>

<provider
android:name=".Database.RecipeContentProvider"
android:authorities="ml.medyas.baknigApp.RecipeContentProvider.provider"
android:enabled="true"
android:exported="true" />

<service
android:name=".Widget.ListWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" >

</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ protected void onCreate(Bundle savedInstanceState) {

if (savedInstanceState != null) {
recipe = savedInstanceState.getParcelable(RECIPE_ITEM);

} else {
recipe = AppSingleton.getSelectedRecipe();
recipe = AppSingleton.getSelectedRecipe();
}

if (findViewById(R.id.right_container) != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ml.medyas.bakingapp.Activities;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -23,6 +24,7 @@ public class RecipeDetailViewActivity extends AppCompatActivity implements Recip
private RecipeClass recipe;
private int position;

@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -50,7 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onSwipeTop() {
}
public void onSwipeRight() {
if(0<position--) {
if(0<position-1) {
position --;
}
else {
Expand All @@ -59,7 +61,7 @@ public void onSwipeRight() {
displayFragment(position);
}
public void onSwipeLeft() {
if(recipe.getSteps().size()<=position++) {
if(recipe.getSteps().size()<=position+1) {
position = 0;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCI
}
return result;
}

}


public void onSwipeRight() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

import java.util.List;

@Entity(tableName = "recipes")
@Entity(tableName = RecipeClass.TABLE_NAME)
public class RecipeClass implements Parcelable {
/** The name of the Cheese table. */
public static final String TABLE_NAME = "recipes";

@PrimaryKey
private int id;
private int servings;
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/ml/medyas/bakingapp/Database/DaoClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.database.Cursor;

import java.util.List;

Expand All @@ -16,6 +17,12 @@ public interface DaoClass {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(List<RecipeClass> recipes);

@Query("select * from recipes ORDER BY id ASC")
@Query("select * from "+ RecipeClass.TABLE_NAME+" ORDER BY id ASC")
LiveData<List<RecipeClass>> getRecipes();

@Query("select * from "+ RecipeClass.TABLE_NAME+" ORDER BY id ASC")
List<RecipeClass> getRecipesList();

@Query("select * from "+ RecipeClass.TABLE_NAME+" ORDER BY id ASC")
Cursor getRecipesCursor();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ml.medyas.bakingapp.Database;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

import ml.medyas.bakingapp.Classes.RecipeClass;

public class RecipeContentProvider extends ContentProvider {

public static final String AUTHORITY = "ml.medyas.baknigApp.RecipeContentProvider.provider";
public static final Uri URI_RECIPE = Uri.parse(
"content://" + AUTHORITY + "/" + RecipeClass.TABLE_NAME);

private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH);

private DaoClass mDao;
private Context context;
/** The match code for some items in the Cheese table. */
private static final int CODE_RECIPE_DIR = 1;

static {
MATCHER.addURI(AUTHORITY, RecipeClass.TABLE_NAME, CODE_RECIPE_DIR);
}

public RecipeContentProvider() {
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
// Implement this to handle requests to delete one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public String getType(Uri uri) {
// TODO: Implement this to handle requests for the MIME type of the data
// at the given URI.
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public Uri insert(Uri uri, ContentValues values) {
// TODO: Implement this to handle requests to insert a new row.
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public boolean onCreate() {
context = getContext();
mDao = RecipesRoomDB.getDatabase(context).recipeDao();
return true;
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
final int code = MATCHER.match(uri);
if (code == CODE_RECIPE_DIR) {
final Cursor cursor;
cursor = mDao.getRecipesCursor();
cursor.setNotificationUri(context.getContentResolver(), uri);
return cursor;
} else {
throw new IllegalArgumentException("Unknown URI: " + uri);
}
}

@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
// TODO: Implement this to handle requests to update one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class RecipesRoomDB extends RoomDatabase {

private static volatile RecipesRoomDB INSTANCE;

static RecipesRoomDB getDatabase(final Context context) {
public static RecipesRoomDB getDatabase(final Context context) {
if (INSTANCE == null) {
synchronized (RecipesRoomDB.class) {
if (INSTANCE == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ml.medyas.bakingapp.Widget;

import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;

import ml.medyas.bakingapp.R;

import static ml.medyas.bakingapp.Widget.RecipesWidget.INGRED_LIST;
import static ml.medyas.bakingapp.Widget.RecipesWidget.ingred;

public class ListWidgetService extends RemoteViewsService {


private String[] mIngred = null;

@Override
public RemoteViewsFactory onGetViewFactory(final Intent intent) {
return new ListWidgetRemoteViewsFactory(this.getApplicationContext(), intent);
}


class ListWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {

private Context mContext;

public ListWidgetRemoteViewsFactory(Context applicationContext, Intent intent) {
mContext = applicationContext;
mIngred = intent.getStringArrayExtra(INGRED_LIST);
}

@Override
public void onCreate() {
}

@Override
public void onDataSetChanged() {
mIngred = ingred;
}

@Override
public void onDestroy() {

}

@Override
public int getCount() {
return mIngred.length;
}

@Override
public RemoteViews getViewAt(int i) {
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_list_item_layout);
rv.setTextViewText(R.id.widget_ingred_text, mIngred[i]);

// Return the remote views object.
return rv;

}

@Override
public RemoteViews getLoadingView() {
return new RemoteViews(mContext.getPackageName(), R.layout.widget_list_item_loading_layout);
}

@Override
public int getViewTypeCount() {
return 1;
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public boolean hasStableIds() {
return false;
}

}
}


Loading

0 comments on commit 7485241

Please sign in to comment.