Kaynağa Gözat

Improvements and fixes in the gallery section

seavenois 10 yıl önce
ebeveyn
işleme
37a0bd2bda

+ 32 - 13
app/src/main/java/com/ivalentin/gm/AlbumLayout.java

@@ -30,9 +30,10 @@ public class AlbumLayout extends Fragment {
     //Main View
     private View view;
 
-    String currLang;
+    private String currLang;
+	private String albumName;
 
-    Context context;
+    private Context context;
 
     @SuppressLint("InflateParams") //Throws unknown error when done properly.
     @Override
@@ -63,16 +64,14 @@ public class AlbumLayout extends Fragment {
         TextView tvTitle = (TextView) view.findViewById(R.id.tv_album_title);
         TextView tvDescription = (TextView) view.findViewById(R.id.tv_album_description);
         tvTitle.setText(cursor.getString(1));
+		albumName = cursor.getString(1);
         if (cursor.getString(2).length() < 1){
             tvDescription.setVisibility(View.GONE);
         }
         else {
             tvDescription.setText(cursor.getString(2));
         }
-        cursor.close();
-
-
-
+		cursor.close();
 
 
         //Assign elements
@@ -92,14 +91,14 @@ public class AlbumLayout extends Fragment {
 			LinearLayout left = (LinearLayout) entry.findViewById(R.id.ll_row_album_left);
 			LinearLayout right = (LinearLayout) entry.findViewById(R.id.ll_row_album_right);
 
-            //Set margins
-            //LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
-            //layoutParams.setMargins(10, 10, 10, 25);
-            //entry.setLayoutParams(layoutParams);
-
             //Set title
             TextView tvTitleLeft = (TextView) entry.findViewById(R.id.tv_row_album_title_left);
-            tvTitleLeft.setText(imageCursor.getString(1));
+			if (imageCursor.getString(1).length() > 0) {
+				tvTitleLeft.setText(imageCursor.getString(1));
+			}
+			else{
+				tvTitleLeft.setVisibility(View.GONE);
+			}
 
             //Set id
             TextView tvHiddenLeft = (TextView) entry.findViewById(R.id.tv_row_album_hidden_left);
@@ -108,6 +107,7 @@ public class AlbumLayout extends Fragment {
             //Set image
             ImageView ivLeft = (ImageView) entry.findViewById(R.id.iv_row_album_left);
             image = imageCursor.getString(2);
+
             //Check if image exists
             File f;
             f = new File(this.getContext().getFilesDir().toString() + "/img/galeria/preview/" + image);
@@ -124,6 +124,12 @@ public class AlbumLayout extends Fragment {
                 new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getContext().getFilesDir().toString() + "/img/galeria/preview/" + image, ivLeft).execute();
             }
 
+			//Count comments
+			Cursor cursorComments = db.rawQuery("SELECT id FROM photo_comment WHERE photo = " + imageCursor.getString(0) + ";", null);
+			TextView tvCommentsLeft = (TextView) entry.findViewById(R.id.tv_row_album_comments_left);
+			tvCommentsLeft.setText(" " + cursorComments.getCount());
+			cursorComments.close();
+
 			//Set onClickListener
 			left.setOnClickListener(new View.OnClickListener(){
 				@Override
@@ -134,6 +140,7 @@ public class AlbumLayout extends Fragment {
 				//Pass post id
 				int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_album_hidden_left)).getText().toString());
 				bundle.putInt("photo", id);
+				bundle.putString("albumName", albumName);
 				fragment.setArguments(bundle);
 
 				FragmentManager fm = AlbumLayout.this.getActivity().getSupportFragmentManager();
@@ -153,7 +160,12 @@ public class AlbumLayout extends Fragment {
 
                 //Set title
                 TextView tvTitleRight = (TextView) entry.findViewById(R.id.tv_row_album_title_right);
-                tvTitleRight.setText(imageCursor.getString(1));
+				if (imageCursor.getString(1).length() > 0) {
+					tvTitleRight.setText(imageCursor.getString(1));
+				}
+				else{
+					tvTitleRight.setVisibility(View.GONE);
+				}
 
                 //Set id
                 TextView tvHiddenRight = (TextView) entry.findViewById(R.id.tv_row_album_hidden_right);
@@ -177,6 +189,12 @@ public class AlbumLayout extends Fragment {
                     new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getContext().getFilesDir().toString() + "/img/galeria/preview/" + image, ivRight).execute();
                 }
 
+				//Count comments
+				cursorComments = db.rawQuery("SELECT id FROM photo_comment WHERE photo = " + imageCursor.getString(0) + ";", null);
+				TextView tvCommentsRight = (TextView) entry.findViewById(R.id.tv_row_album_comments_right);
+				tvCommentsRight.setText(" " + cursorComments.getCount());
+				cursorComments.close();
+
 				//Set onClickListener
 				right.setOnClickListener(new View.OnClickListener(){
 					@Override
@@ -186,6 +204,7 @@ public class AlbumLayout extends Fragment {
 					//Pass post id
 					int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_album_hidden_right)).getText().toString());
 					bundle.putInt("photo", id);
+					bundle.putString("albumName", albumName);
 					fragment.setArguments(bundle);
 
 					FragmentManager fm = AlbumLayout.this.getActivity().getSupportFragmentManager();

+ 19 - 7
app/src/main/java/com/ivalentin/gm/PhotoLayout.java

@@ -32,6 +32,7 @@ public class PhotoLayout extends Fragment {
 	private View view;
 
 	String currLang;
+	String albumName;
 
 	Integer photos[];
 	int position;
@@ -48,6 +49,7 @@ public class PhotoLayout extends Fragment {
 
 		//Get bundled id
 		Bundle bundle = this.getArguments();
+		albumName = bundle.getString(albumName, "");
 		int id = bundle.getInt("photo", -1);
 		if (id == -1) {
 			//TODO: Error, do something
@@ -142,16 +144,26 @@ public class PhotoLayout extends Fragment {
 		LinearLayout llCommentList = (LinearLayout) v.findViewById(R.id.ll_comment_list);
 
 		//Set fields
-		tvTitle.setText(cursor.getString(2));
-		((MainActivity) getActivity()).setSectionTitle(cursor.getString(2));
-		tvDescription.setText(cursor.getString(3));
-		tvDate.setText(GM.formatDate(cursor.getString(4), currLang, true));
+		if (cursor.getString(2).length() > 0) {
+			tvTitle.setVisibility(View.VISIBLE);
+			tvTitle.setText(cursor.getString(2));
+			((MainActivity) getActivity()).setSectionTitle(cursor.getString(2));
+		}
+		else{
+			tvTitle.setVisibility(View.GONE);
+			((MainActivity) getActivity()).setSectionTitle(albumName);
+		}
 
-		//Close the cursor
-		//cursor.close();
+		if (cursor.getString(3).length() > 0) {
+			tvDescription.setVisibility(View.VISIBLE);
+			tvDescription.setText(cursor.getString(3));
+		}
+		else{
+			tvDescription.setVisibility(View.GONE);
+		}
+		tvDate.setText(GM.formatDate(cursor.getString(4), currLang, true));
 
 		//Get image
-
 		String image = cursor.getString(1);
 
 		//Check if image exists

+ 2 - 1
app/src/main/res/layout/fragment_layout_photo.xml

@@ -49,7 +49,8 @@
                 android:textAppearance="?android:attr/textAppearanceSmall"
                 android:text="Small Text"
                 android:id="@+id/tv_photo_date"
-                android:layout_marginLeft="15dp"/>
+                android:layout_marginLeft="15dp"
+                android:layout_marginBottom="15dp"/>
 
             <LinearLayout
                 android:orientation="horizontal"