Skip to content

Commit

Permalink
Add button to the user login view to register on the website
Browse files Browse the repository at this point in the history
  • Loading branch information
Scot SCRIVEN authored and Scot SCRIVEN committed Apr 17, 2016
1 parent 6f9252e commit 16cb61b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
Expand All @@ -19,6 +21,7 @@
import org.apache.http.Header;
import openfoodfacts.github.scrachx.openfood.R;
import openfoodfacts.github.scrachx.openfood.network.FoodUserClient;
import openfoodfacts.github.scrachx.openfood.utils.Utils;

/**
* Created by scotscriven on 08/05/15.
Expand All @@ -28,6 +31,7 @@ public class UserFragment extends Fragment {
EditText login, pass;
TextView infoLogin;
Button save;
Button signup;

@Nullable
@Override
Expand All @@ -41,6 +45,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
pass = (EditText) rootView.findViewById(R.id.editTextPass);
save = (Button) rootView.findViewById(R.id.buttonSave);
infoLogin = (TextView) rootView.findViewById(R.id.textInfoLogin);
signup = (Button) rootView.findViewById(R.id.buttonCreateAccount);

login.setSelected(false);
pass.setSelected(false);
Expand All @@ -57,6 +62,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
login.setText(loginS);
pass.setText(passS);

signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browser = new Intent(Intent.ACTION_VIEW);
browser.setData(Uri.parse(Utils.getUriByCurrentLanguage() + "cgi/user.pl"));
startActivity(browser);
}
});

save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;

/**
* @author Eddie
*
*/
public class Utils {

public static String getUriByCurrentLanguage() {
String url;
if (Locale.getDefault().getLanguage().contains("fr")){
url = "http://fr.openfoodfacts.org/";
} else {
url = "http://world.openfoodfacts.org/";
}
return url;
}

public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
style="@style/DefaultButtonText"
android:layout_gravity="center"
android:gravity="center"
android:layout_alignParentBottom="true"
android:text="@string/try_it_scan_now"
android:id="@+id/buttonScan"
/>
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/fragment_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@
android:id="@+id/textInfoLogin"
android:layout_gravity="center_horizontal" />


</LinearLayout>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_default_bg"
style="@style/DefaultButtonText"
android:text="@string/create_account"
android:padding="@dimen/spacing_small"
android:id="@+id/buttonCreateAccount"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />

</RelativeLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@
<string name="try_it_scan_now">Scanner!</string>
<string name="share">Partager</string>
<string name="msg_share">Regarde ce produit sur Open Food Facts :</string>
<string name="create_account">S\'inscrire</string>
</resources>
7 changes: 4 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">OpenFood</string>
<string name="app_name">Open Food</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="action_about">About</string>
Expand Down Expand Up @@ -113,11 +113,11 @@
<string name="txtNoData">No data</string>
<string name="txtPictureNeeded">Take a picture first, then fill the name and store!</string>
<string name="toastSending">Uploading...</string>
<string name="dataSaved">Saved locally on your phone</string>
<string name="dataSaved">Saved locally on your device</string>
<string name="txtInfoAddUser">Please enter your login and password</string>
<string name="txtDataUpdated">Data updated</string>
<string name="txtLoading">Loading...</string>
<string name="txtDialogsContentDelete">Do you want to delete this entry?</string>
<string name="txtDialogsContentDelete">Do you want to delete this draft?</string>
<string name="txtDialogsContentInfoSave">The product is saved locally, you can edit it in the "Offline Edit" menu</string>
<string name="txtBarcodeRequire">Barcode required</string>
<string name="txtOk">Ok</string>
Expand All @@ -129,6 +129,7 @@
<string name="try_it_scan_now">Try it! Scan now!</string>
<string name="share">Share</string>
<string name="msg_share">Look at this product on Open Food Facts :</string>
<string name="create_account">Sign up</string>

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

0 comments on commit 16cb61b

Please sign in to comment.