Skip to content

Commit

Permalink
Add edit product button (on web)
Browse files Browse the repository at this point in the history
Close #76
  • Loading branch information
itchix committed May 15, 2016
1 parent a86f47d commit 8c748a4
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
Binary file modified app/app-release.apk
Binary file not shown.
10 changes: 5 additions & 5 deletions app/build.gradle
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "openfoodfacts.github.scrachx.openfood"
minSdkVersion 15
targetSdkVersion 23
versionCode 19
versionName "0.2.1"
versionCode 20
versionName "0.2.2"
}

dexOptions {
Expand Down Expand Up @@ -56,10 +56,10 @@ apply plugin: 'com.neenbedankt.android-apt'

dependencies {

compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.4.0'

compile 'com.jakewharton:butterknife:7.0.1'

Expand Down
Expand Up @@ -7,8 +7,12 @@
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;

import com.afollestad.materialdialogs.MaterialDialog;
import com.mikepenz.fastadapter.utils.RecyclerViewCacheUtil;
import com.mikepenz.fontawesome_typeface_library.FontAwesome;
import com.mikepenz.materialdrawer.AccountHeader;
Expand Down Expand Up @@ -184,4 +188,25 @@ public void onBackPressed() {
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.action_about:
new MaterialDialog.Builder(this)
.title(R.string.action_about)
.content(R.string.txtAbout)
.negativeText(R.string.txtOk)
.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
@@ -1,6 +1,7 @@
package openfoodfacts.github.scrachx.openfood.views;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v4.view.MenuItemCompat;
Expand All @@ -25,6 +26,7 @@ public class ProductActivity extends BaseActivity {
private ShareActionProvider mShareActionProvider;
private ProductPagerAdapter adapterResult;
private List<Allergen> mAllergens;
private State mState;

@Bind(R.id.pager) ViewPager viewPager;
@Bind(R.id.toolbar) Toolbar toolbar;
Expand All @@ -44,10 +46,10 @@ protected void onCreate(Bundle savedInstanceState) {
viewPager.setAdapter(adapterResult);

Intent intent = getIntent();
State state = (State) intent.getExtras().getSerializable("state");
mState = (State) intent.getExtras().getSerializable("state");

List<String> all = (List<String>) state.getProduct().getAllergensHierarchy();
List<String> traces = (List<String>) state.getProduct().getTracesTags();
List<String> all = (List<String>) mState.getProduct().getAllergensHierarchy();
List<String> traces = (List<String>) mState.getProduct().getTracesTags();
all.addAll(traces);
List<String> matchAll = new ArrayList<String>();
for (int a = 0; a < mAllergens.size(); a++) {
Expand Down Expand Up @@ -77,24 +79,29 @@ public boolean onOptionsItemSelected(MenuItem item) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.action_edit_product:
String url = Utils.getUriProductByCurrentLanguage() + mState.getProduct().getCode();
if (mState.getProduct().getUrl() != null) {
url = " " + mState.getProduct().getUrl();
}
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
default:
return super.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_product_share, menu);
getMenuInflater().inflate(R.menu.menu_product, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);

Intent intent = getIntent();
State state = (State) intent.getExtras().getSerializable("state");

Intent shareIntent = new Intent(Intent.ACTION_SEND);
String url = " " + Utils.getUriProductByCurrentLanguage() + state.getProduct().getCode();
if (state.getProduct().getUrl() != null) {
url = " " + state.getProduct().getUrl();
String url = " " + Utils.getUriProductByCurrentLanguage() + mState.getProduct().getCode();
if (mState.getProduct().getUrl() != null) {
url = " " + mState.getProduct().getUrl();
}
shareIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.msg_share) + url);
shareIntent.setType("text/plain");
Expand Down
Expand Up @@ -7,4 +7,9 @@
android:title="@string/share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider" />

<item android:id="@+id/action_edit_product"
android:icon="@android:drawable/ic_menu_edit"
android:title="@string/action_edit_product"
app:showAsAction="ifRoom" />

</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -144,6 +144,7 @@
<string name="warning_alert_data">Data may not be accurate, be careful, please check by yourself!</string>
<string name="from_gallery">From gallery</string>
<string name="product_sent">Product sent!</string>
<string name="action_edit_product">Edit product</string>

<style name="DefaultButtonText">
<item name="android:layout_width">fill_parent</item>
Expand Down

0 comments on commit 8c748a4

Please sign in to comment.