Parcourir la source

Sponsor section completed.

seavenois il y a 9 ans
Parent
commit
02c96ffc68

+ 154 - 9
app/src/main/java/com/ivalentin/margolariak/SponsorActivity.java

@@ -1,26 +1,35 @@
 package com.ivalentin.margolariak;
 
+import android.annotation.SuppressLint;
 import android.app.Activity;
-import android.content.Context;
+import android.app.Dialog;
 import android.content.Intent;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.net.Uri;
 import android.os.Bundle;
-import android.util.Log;
+import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.Window;
+import android.view.WindowManager;
+import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
-import android.widget.RelativeLayout;
 import android.widget.TextView;
 
+
 import java.io.File;
 
 /**
- * Created by seavenois on 26/09/16.
+ * Activity that lists sponsors.
+ *
+ * @author Iñigo Valentin
+ *
+ * @see Activity
+ *
  */
 public class SponsorActivity extends Activity {
 
@@ -30,6 +39,7 @@ public class SponsorActivity extends Activity {
 	 * @param savedInstanceState Saved state of the activity.
 	 * @see Activity#onCreate(Bundle)
 	 */
+	@SuppressLint("InflateParams")
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 
@@ -56,12 +66,16 @@ public class SponsorActivity extends Activity {
 			//Create a new row
 			entry = (LinearLayout) factory.inflate(R.layout.row_sponsor, null);
 
-			//Set margins TODO: I dont know why it doesnt read margins from the xml
+			//Set margins TODO: I don't know why it doesnt read margins from the xml
 			LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
 			int margin = (int) (9 * getResources().getDisplayMetrics().density);
 			layoutParams.setMargins(margin, margin, margin, margin);
 			entry.setLayoutParams(layoutParams);
 
+			//Set id (hidden)
+			TextView tvId = (TextView) entry.findViewById(R.id.tv_row_sponsor_id);
+			tvId.setText(cursor.getString(0));
+
 			//Set title
 			TextView tvTitle = (TextView) entry.findViewById(R.id.tv_row_sponsor_name);
 			tvTitle.setText(cursor.getString(1));
@@ -73,7 +87,7 @@ public class SponsorActivity extends Activity {
 			//Set image
 			ImageView ivImage = (ImageView) entry.findViewById(R.id.iv_row_sponsor_image);
 			//Check if image exists
-			if (cursor.getString(3) != null && "".equals(cursor.getString(3)) == false) {
+			if (cursor.getString(3) != null && !"".equals(cursor.getString(3))) {
 				String image = cursor.getString(3);
 				File f;
 				f = new File(getFilesDir().toString() + "/img/spo/preview/" + image);
@@ -94,9 +108,15 @@ public class SponsorActivity extends Activity {
 				ivImage.setVisibility(View.GONE);
 			}
 
-
-			//TODO: Set onClick listener
-
+			//Set onClick listener
+			entry.setOnClickListener(new View.OnClickListener() {
+				@Override
+				public void onClick(View v) {
+					TextView tvId = (TextView) v.findViewById(R.id.tv_row_sponsor_id);
+					int id = Integer.parseInt(tvId.getText().toString());
+					openDialog(id);
+				}
+			});
 
 
 			llList.addView(entry);
@@ -106,6 +126,131 @@ public class SponsorActivity extends Activity {
 
 	}
 
+	/**
+	 * Shows a dialog with info about the selected event.
+	 *
+	 * @param id The event id
+	 */
+	@SuppressWarnings("ConstantConditions")
+	private void openDialog(final int id){
+
+		//Create the dialog
+		final Dialog dialog = new Dialog(this);
+
+		//Set up dialog window
+		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+		dialog.setContentView(R.layout.dialog_sponsor);
+
+		//Set the custom dialog components - text, image and button
+		TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_sponsor_title);
+		TextView tvText = (TextView) dialog.findViewById(R.id.tv_dialog_sponsor_text);
+		ImageView ivImage = (ImageView) dialog.findViewById(R.id.iv_dialog_sponsor_image);
+		TextView tvUrl = (TextView) dialog.findViewById(R.id.tv_dialog_sponsor_url);
+		TextView tvAddress = (TextView) dialog.findViewById(R.id.tv_dialog_sponsor_address);
+		Button btClose = (Button) dialog.findViewById(R.id.bt_dialog_sponsor_close);
+		LinearLayout llUrl = (LinearLayout) dialog.findViewById(R.id.ll_dialog_sponsor_url);
+		LinearLayout llAddress = (LinearLayout) dialog.findViewById(R.id.ll_dialog_sponsor_address);
+
+		//Get info about the event
+		SQLiteDatabase db = SQLiteDatabase.openDatabase(getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
+		String lang = GM.getLang();
+		Cursor cursor = db.rawQuery("SELECT id, name_" + lang + " AS name, text_" + lang + " AS text, image, address_" + lang + " AS address, link, lat, lon FROM sponsor WHERE id = " + id + ";", null);
+		if (cursor.getCount() > 0){
+			cursor.moveToNext();
+
+			//Set title
+			tvTitle.setText(cursor.getString(1));
+
+			//Set description
+			tvText.setText(cursor.getString(2));
+
+			//Set image (if any)
+			if (cursor.getString(3) != null && !"".equals(cursor.getString(3))){
+				File f;
+				f = new File(getFilesDir().toString() + "/img/spo/preview/" + cursor.getString(3));
+				if (f.exists()){
+					//If the image exists, set it.
+					Bitmap myBitmap = BitmapFactory.decodeFile(getFilesDir().toString() + "/img/spo/preview/" + cursor.getString(3));
+					ivImage.setImageBitmap(myBitmap);
+				}
+				else {
+					//If not, create directories and download asynchronously
+					File fpath;
+					fpath = new File(getFilesDir().toString() + "/img/spo/preview/");
+					//noinspection ResultOfMethodCallIgnored
+					fpath.mkdirs();
+					new DownloadImage(GM.API.SERVER + "/img/spo/preview/" + cursor.getString(3), getFilesDir().toString() + "/img/spo/preview/" + cursor.getString(3), ivImage, GM.IMG.SIZE.PREVIEW).execute();
+				}
+				ivImage.setVisibility(View.VISIBLE);
+			}
+			else{
+				ivImage.setVisibility(View.GONE);
+			}
+
+			//Set address (if any)
+			if (cursor.getString(4) != null && !"".equals(cursor.getString(4))){
+				final String lat = cursor.getString(6);
+				final String lon = cursor.getString(7);
+				tvAddress.setText(cursor.getString(4));
+				tvAddress.setOnClickListener(new View.OnClickListener() {
+					@Override
+					public void onClick(View v) {
+						String url = "https://www.google.com/maps/preview/@" + lat + "," + lon + ",8z";
+						Intent i = new Intent(Intent.ACTION_VIEW);
+						i.setData(Uri.parse(url));
+						startActivity(i);
+					}
+				});
+			}
+			else{
+				llAddress.setVisibility(View.GONE);
+			}
+
+			//Set url (if any)
+			if (cursor.getString(5) != null && !"".equals(cursor.getString(3))){
+				final String url = cursor.getString(5);
+				tvUrl.setOnClickListener(new View.OnClickListener() {
+					@Override
+					public void onClick(View v) {
+						Intent i = new Intent(Intent.ACTION_VIEW);
+						i.setData(Uri.parse(url));
+						startActivity(i);
+					}
+				});
+			}
+			else{
+				llUrl.setVisibility(View.GONE);
+			}
+
+			//Close the db connection
+			cursor.close();
+			db.close();
+
+			//Set close button
+			btClose.setOnClickListener(new View.OnClickListener() {
+				@Override
+				public void onClick(View v) {
+					dialog.dismiss();
+				}
+			});
+
+
+
+			//Show the dialog
+			WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
+			lp.copyFrom(dialog.getWindow().getAttributes());
+			lp.width = WindowManager.LayoutParams.MATCH_PARENT;
+			lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
+			lp.gravity = Gravity.CENTER;
+			dialog.getWindow().setAttributes(lp);
+
+			//Show dialog
+			dialog.show();
+
+
+		}
+	}
+
 
 	/**
 	 * Not called from code, but referenced from activity_sponsor.xml.

BIN
app/src/main/res/drawable/web.png


+ 10 - 3
app/src/main/res/layout/activity_sponsor.xml

@@ -72,7 +72,8 @@
     <ScrollView
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
-        android:background="@color/background_app">
+        android:background="@color/background_app"
+        >
 
         <LinearLayout
             android:id="@+id/ll_sponsors_section"
@@ -80,7 +81,12 @@
             android:layout_height="wrap_content"
             android:orientation="vertical"
             android:background="@drawable/section"
-            android:layout_margin="10dp">
+            android:layout_marginBottom="40dp"
+            android:layout_marginEnd="10dp"
+            android:layout_marginLeft="10dp"
+            android:layout_marginRight="10dp"
+            android:layout_marginStart="10dp"
+            android:layout_marginTop="10dp">
 
             <TextView
                 android:layout_width="match_parent"
@@ -102,7 +108,8 @@
                 android:orientation="vertical"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:id="@+id/ll_sponsor_list">
+                android:id="@+id/ll_sponsor_list"
+                android:layout_marginBottom="20dp">
             </LinearLayout>
 
         </LinearLayout>

+ 128 - 0
app/src/main/res/layout/dialog_sponsor.xml

@@ -0,0 +1,128 @@
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:background="@drawable/section"
+    android:paddingBottom="15dp">
+
+    <TextView
+        android:id="@+id/tv_dialog_sponsor_title"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceLarge"
+        android:textStyle="bold"
+        android:background="@drawable/section_title"
+        android:paddingBottom="4dp"
+        android:paddingEnd="10dp"
+        android:paddingLeft="20dp"
+        android:paddingRight="10dp"
+        android:paddingStart="20dp"
+        android:paddingTop="4dp"
+        android:textColor="@color/section_title"
+        android:layout_alignParentTop="true"/>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="fill_parent"
+        android:orientation="vertical"
+        android:background="@drawable/entry"
+        android:layout_margin="8dp"
+        android:padding="7dp"
+        >
+
+        <ImageView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            app:srcCompat="@drawable/photo_placeholder_thumb"
+            android:id="@+id/iv_dialog_sponsor_image"
+            android:maxHeight="140dp"
+            android:adjustViewBounds="true"/>
+
+        <TextView
+            android:id="@+id/tv_dialog_sponsor_text"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_margin="7dp"
+            android:textAppearance="@android:style/TextAppearance.Medium"/>
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                android:id="@+id/ll_dialog_sponsor_url">
+
+                <ImageView
+                    android:layout_width="30dp"
+                    android:layout_height="30dp"
+                    android:layout_marginBottom="20dp"
+                    android:layout_marginStart="15dp"
+                    android:layout_marginRight="15dp"
+                    android:layout_marginLeft="15dp"
+                    android:layout_marginEnd="15dp"
+                    android:layout_marginTop="20dp"
+                    android:adjustViewBounds="true"
+                    android:src="@drawable/web"/>
+
+                <TextView
+                    android:text="@string/sponsors_url"
+                    android:layout_height="match_parent"
+                    android:id="@+id/tv_dialog_sponsor_url"
+                    android:layout_weight="1"
+                    android:gravity="center_vertical"
+                    android:layout_width="match_parent"
+                    android:textColor="@color/background_menu"
+                    android:textSize="16sp"
+                    android:textStyle="normal|bold"/>
+            </LinearLayout>
+
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                android:id="@+id/ll_dialog_sponsor_address">
+
+                <ImageView
+                    android:layout_width="30dp"
+                    android:layout_height="30dp"
+                    android:adjustViewBounds="false"
+                    android:layout_marginBottom="20dp"
+                    android:layout_marginStart="15dp"
+                    android:layout_marginRight="15dp"
+                    android:layout_marginLeft="15dp"
+                    android:layout_marginEnd="15dp"
+                    android:layout_marginTop="20dp"
+                    android:src="@drawable/pinpoint"/>
+
+                <TextView
+                    android:layout_height="match_parent"
+                    android:id="@+id/tv_dialog_sponsor_address"
+                    android:layout_weight="1"
+                    android:gravity="center_vertical"
+                    android:layout_width="match_parent"
+                    android:textStyle="normal|bold"
+                    android:textSize="16sp"
+                    android:textColor="@color/background_menu"/>
+            </LinearLayout>
+        </LinearLayout>
+
+    </LinearLayout>
+
+    <Button
+        android:id="@+id/bt_dialog_sponsor_close"
+        android:layout_width="match_parent"
+        android:layout_margin="5dp"
+        android:background="@drawable/button_selector"
+        android:text="@string/notification_close"
+        android:textColor="@color/input_text_color"
+        android:textStyle="bold"
+        android:layout_alignParentBottom="true"
+        android:layout_height="50dp"/>
+
+</LinearLayout>

+ 1 - 1
app/src/main/res/layout/row_sponsor.xml

@@ -20,7 +20,7 @@
     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:id="@+id/tv_row_sponsor_hidden"
+        android:id="@+id/tv_row_sponsor_id"
         android:visibility="gone" />
 
     <LinearLayout

+ 1 - 0
app/src/main/res/values-en/strings.xml

@@ -165,6 +165,7 @@
 	<string name="pop_menu_about">About us</string>
 	<string name="pop_menu_settings">Settings</string>
 	<string name="pop_menu_sponsors">Sponsors</string>
+	<string name="sponsors_url">Open web site</string>
 	<string name="preferences">Preferences</string>
 	<string name="preferences_info">Information</string>
 	<string name="preferences_info_feedback">Feedback</string>

+ 1 - 0
app/src/main/res/values-eu-rES/strings.xml

@@ -170,6 +170,7 @@
 	<string name="pop_menu_about">Gu</string>
 	<string name="pop_menu_settings">Ajustes</string>
 	<string name="pop_menu_sponsors">Patrocinadores</string>
+	<string name="sponsors_url">Web horria</string>
 	<string name="preferences_info">Informazioa</string>
 	<string name="preferences_info_feedback_summary">Send anonymous feedback to the developer</string>
 	<string name="preferences_info_source">Codigo fuente</string>

+ 3 - 0
app/src/main/res/values/strings.xml

@@ -186,6 +186,9 @@
 	<string name="pop_menu_sponsors">Patrocinadores</string>
 	<string name="pop_menu_about">Sobre nosotros</string>
 
+	<!-- Sponsors -->
+	<string name="sponsors_url">Sitio web</string>
+
 	<!--Preferences screen-->
 	<string name="preferences">Preferencias</string>
 	<string name="preferences_sync">Sincronización</string>

+ 2 - 2
gradle.properties

@@ -1,4 +1,4 @@
 org.gradle.daemon=true
-org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+org.gradle.jvmargs=-Xmx2560m -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
 org.gradle.parallel=true
-org.gradle.configureondemand=true
+org.gradle.configureondemand=true