Ver Fonte

Comments and sync stats

seavenois há 10 anos atrás
pai
commit
babba175fd

+ 1 - 1
app/src/main/java/com/ivalentin/margolariak/MainActivity.java

@@ -263,7 +263,7 @@ public class MainActivity extends Activity{
 		//If the user code is not set, generate one
 		if (preferences.getString(GM.USER_CODE, "").length() == 0){
 			SecureRandom random = new SecureRandom();
-			String newCode = new BigInteger(130, random).toString(32).substring(0, 8);
+			String newCode = new BigInteger(130, random).toString(32).substring(0, 16);
 			SharedPreferences.Editor editor = preferences.edit();
 			editor.putString(GM.USER_CODE, newCode);
 			editor.apply();

+ 2 - 1
app/src/main/java/com/ivalentin/margolariak/PhotoLayout.java

@@ -208,7 +208,8 @@ public class PhotoLayout extends Fragment {
 			imageView.setImageBitmap(myBitmap);
 		}
 		else {
-			//If not, create directories and download asynchronously
+			//If not,  set placeholder image, create directories and download asynchronously
+			imageView.setImageResource(getResources().getIdentifier("com.ivalentin.margolariak:drawable/pinpoint_gm", null, null));
 			File fpath;
 			fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/view/");
 			fpath.mkdirs();

+ 16 - 10
app/src/main/java/com/ivalentin/margolariak/PostComment.java

@@ -2,6 +2,7 @@ package com.ivalentin.margolariak;
 
 import android.annotation.SuppressLint;
 import android.content.Context;
+import android.content.SharedPreferences;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.AsyncTask;
 import android.text.format.DateFormat;
@@ -23,17 +24,17 @@ import java.util.Date;
 class PostComment extends AsyncTask<String, String, Integer> {
 
     //Elements passed from fragments
-    String type, user, text, language;
-    LinearLayout list, form;
-    TextView counter;
-    int id, currentCounter;
-    Context context;
+    private String type, user, text, language, userCode;
+    private LinearLayout list, form;
+    private TextView counter;
+    private int id, currentCounter;
+    private Context context;
 
     //Elements calculated here
-    Button btSend;
-    ProgressBar pb;
+    private Button btSend;
+    private ProgressBar pb;
 
-    int code = 404;
+    private int code = 404;
 
     public PostComment(String type, String user, String text, String language, int id, LinearLayout form, LinearLayout list, int currentCounter, TextView counter, Context context) {
         super();
@@ -47,6 +48,7 @@ class PostComment extends AsyncTask<String, String, Integer> {
         this.id = id;
         this.currentCounter = currentCounter;
         this.context = context;
+
     }
 
     /**
@@ -59,6 +61,10 @@ class PostComment extends AsyncTask<String, String, Integer> {
         pb = (ProgressBar) form.findViewById(R.id.pb_comment);
         btSend.setVisibility(View.GONE);
         pb.setVisibility(View.VISIBLE);
+
+        //Get user code
+        SharedPreferences preferences = context.getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+        userCode = preferences.getString(GM.USER_CODE, "");
     }
 
     /**
@@ -94,10 +100,10 @@ class PostComment extends AsyncTask<String, String, Integer> {
                     urlParams = urlParams + "&lang=eu";
                     break;
                 default:
-                    this.language = "en";
                     urlParams = urlParams + "&lang=en";
             }
-
+            urlParams = urlParams + "&from=app&code=" + userCode;
+            Log.e("PARAMS", urlParams);
             byte[] postData       = urlParams.getBytes("UTF-8");
             int    postDataLength = postData.length;
             String request        = GM.SERVER + "/" + type + "/comment.php";

+ 2 - 2
app/src/main/java/com/ivalentin/margolariak/PostLayout.java

@@ -52,7 +52,7 @@ public class PostLayout extends Fragment {
 
         //Get bundled id
         Bundle bundle = this.getArguments();
-        int id = bundle.getInt("post", -1);
+        final int id = bundle.getInt("post", -1);
         if (id == -1){
             Log.e("Post error", "No such post: " + id);
             this.getActivity().onBackPressed();
@@ -164,7 +164,7 @@ public class PostLayout extends Fragment {
                 //Start async task
                 LinearLayout form = (LinearLayout) view.findViewById(R.id.ll_new_comment);
                 LinearLayout list = (LinearLayout) view.findViewById(R.id.ll_comment_list);
-                new PostComment("blog", user, text, currLang, cursor.getInt(0), form, list, commentCount, tvComments, context).execute();
+                new PostComment("blog", user, text, currLang, id, form, list, commentCount, tvComments, context).execute();
 
             }
         });

+ 5 - 6
app/src/main/java/com/ivalentin/margolariak/Sync.java

@@ -30,7 +30,7 @@ public class Sync extends AsyncTask<Void, Void, Void> {
 	private ProgressBar pbSync;
 	private Dialog dialog;
 	private MainActivity activity;
-	private boolean fg;
+	private int fg;
 	private int newVersion;
 	private String strings[];
 	private boolean doProgress = false;
@@ -122,7 +122,7 @@ public class Sync extends AsyncTask<Void, Void, Void> {
         this.myContextRef = myContextRef;
         dialog = null;
         pbSync = pb;
-        fg = true;
+        fg = 1;
     }
     
     /**
@@ -140,7 +140,7 @@ public class Sync extends AsyncTask<Void, Void, Void> {
     	this.activity = activity;
         this.myContextRef = myContextRef;
         pbSync = pb;
-        fg = true;
+        fg = 1;
     }
     
     /**
@@ -151,7 +151,7 @@ public class Sync extends AsyncTask<Void, Void, Void> {
     public Sync(Context context) {
         this.myContextRef = context;
         pbSync = null;
-        fg = false;
+        fg = 0;
     }
 
 	@Override
@@ -208,11 +208,10 @@ public class Sync extends AsyncTask<Void, Void, Void> {
 		try{
 			publishProgress();
 
-			String user = preferences.getString(GM.USER_NAME, "");
 			String code = preferences.getString(GM.USER_CODE, "");
 			int dbVersion = preferences.getInt(GM.PREF_DB_VERSION, GM.DEFAULT_PREF_DB_VERSION);
 			fu = new FetchURL();
-			fu.Run(GM.SERVER + "/app/sync.php?user=" + user + "&code=" + code + "&fg=" + fg + "&v=" + dbVersion);
+			fu.Run(GM.SERVER + "/app/sync.php?os=android&code=" + code + "&fg=" + fg + "&v=" + dbVersion);
 			//All the info
 			o = fu.getOutput().toString();
 			publishProgress();