Преглед на файлове

Sponsor list implemented.

seavenois преди 9 години
родител
ревизия
c2627706c8

+ 113 - 0
app/src/main/java/com/ivalentin/margolariak/SponsorActivity.java

@@ -1,9 +1,122 @@
 package com.ivalentin.margolariak;
 
 import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.Window;
+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.
  */
 public class SponsorActivity extends Activity {
+
+	/**
+	 * Runs when the activity is created.
+	 *
+	 * @param savedInstanceState Saved state of the activity.
+	 * @see Activity#onCreate(Bundle)
+	 */
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+
+		//Remove title bar.
+		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+		super.onCreate(savedInstanceState);
+
+		//Set layout.
+		setContentView(R.layout.activity_sponsor);
+
+		//Assign menu items
+		LinearLayout llList = (LinearLayout) findViewById(R.id.ll_sponsor_list);
+		LinearLayout entry;
+		LayoutInflater factory = LayoutInflater.from(this);
+
+		//Get data from database
+		SQLiteDatabase db = SQLiteDatabase.openDatabase(getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
+		final Cursor cursor;
+		String lang = GM.getLang();
+		cursor = db.rawQuery("SELECT id, name_" + lang + " AS name, text_" + lang + " AS text, image, address_" + lang + " AS address, link, lat, lon FROM sponsor ORDER BY RANDOM();", null);
+		cursor.moveToFirst();
+
+		while (cursor.moveToNext()) {
+			//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
+			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 title
+			TextView tvTitle = (TextView) entry.findViewById(R.id.tv_row_sponsor_name);
+			tvTitle.setText(cursor.getString(1));
+
+			//Set text
+			TextView tvText = (TextView) entry.findViewById(R.id.tv_row_sponsor_text);
+			tvText.setText(cursor.getString(2));
+
+			//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) {
+				String image = cursor.getString(3);
+				File f;
+				f = new File(getFilesDir().toString() + "/img/spo/preview/" + image);
+				if (f.exists()) {
+					//If the image exists, set it.
+					Bitmap myBitmap = BitmapFactory.decodeFile(getFilesDir().toString() + "/img/spo/preview/" + image);
+					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/" + image, getFilesDir().toString() + "/img/spo/preview/" + image, ivImage, GM.IMG.SIZE.PREVIEW).execute();
+				}
+			}
+			else{
+				ivImage.setVisibility(View.GONE);
+			}
+
+
+			//TODO: Set onClick listener
+
+
+
+			llList.addView(entry);
+		}
+		cursor.close();
+		db.close();
+
+	}
+
+
+	/**
+	 * Not called from code, but referenced from activity_sponsor.xml.
+	 * Finishes the activity.
+	 *
+	 * @param v Ignored
+	 *
+	 * @see Activity#finish()
+	 */
+	public void finish(View v){
+		finish();
+	}
+
 }

+ 112 - 0
app/src/main/res/layout/activity_sponsor.xml

@@ -0,0 +1,112 @@
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical"
+    android:background="@color/background_app">
+
+    <LinearLayout
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:background="@color/background_menu"
+        android:gravity="center_vertical"
+        android:orientation="horizontal"
+        android:padding="2dp">
+
+        <ImageView
+            android:contentDescription="@string/app_name"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:id="@+id/iv_logo"
+            android:src="@drawable/ic_launcher"
+            android:adjustViewBounds="true"
+            android:layout_weight=".2"
+            android:maxHeight="45dp"
+            android:maxWidth="45dp"
+            android:padding="1dp"
+            android:layout_gravity="center_vertical"/>
+
+        <LinearLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical|center"
+            android:layout_weight=".8"
+            android:gravity="center"
+            android:orientation="vertical" >
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:gravity="center"
+                android:text="@string/app_name"
+                android:contentDescription="@string/app_name"
+                android:textSize="18sp"
+                android:textStyle="bold"
+                android:textColor="@color/menu_entry"/>
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:gravity="center"
+                android:text="@string/pop_menu_sponsors"
+                android:textSize="20sp"
+                android:textColor="@color/menu_entry"/>
+
+        </LinearLayout>
+
+        <ImageButton
+            android:layout_width="40dp"
+            android:layout_height="match_parent"
+            android:src="@android:drawable/ic_menu_revert"
+            android:onClick="finish"
+            android:contentDescription="@string/accept"
+            android:layout_weight=".2"
+            android:id="@+id/bt_back"
+            app:srcCompat="@android:drawable/ic_menu_revert"
+            android:background="#00000000"/>
+
+    </LinearLayout>
+
+    <ScrollView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:background="@color/background_app">
+
+        <LinearLayout
+            android:id="@+id/ll_sponsors_section"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical"
+            android:background="@drawable/section"
+            android:layout_margin="10dp">
+
+            <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/pop_menu_sponsors"
+                android:textAppearance="?android:attr/textAppearanceLarge"
+                android:textStyle="bold"
+                tools:layout_width="match_parent"
+                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"/>
+
+            <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:id="@+id/ll_sponsor_list">
+            </LinearLayout>
+
+        </LinearLayout>
+    </ScrollView>
+
+</LinearLayout>
+

+ 75 - 0
app/src/main/res/layout/row_sponsor.xml

@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:background="@drawable/entry"
+    android:padding="7dp"
+    android:layout_margin="8dp">
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textColor="@color/entry_title"
+        android:textStyle="bold"
+        android:id="@+id/tv_row_sponsor_name" />
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/tv_row_sponsor_hidden"
+        android:visibility="gone" />
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/iv_row_sponsor_image"
+            android:maxWidth="110dp"
+            android:contentDescription="@string/app_cdesc"
+            android:minHeight="30dp"
+            android:minWidth="30dp"
+            android:layout_gravity="top|center_vertical"
+            android:background="@color/image_border"
+            android:padding="0.5dp"
+            android:layout_margin="3dp"
+            android:adjustViewBounds="true"
+            android:maxHeight="100dp"/>
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="top">
+
+            <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:id="@+id/tv_row_sponsor_text"
+                android:textAppearance="@android:style/TextAppearance.Medium"
+                android:layout_margin="5dp"
+                android:maxLines="4"
+                android:minHeight="30dp"/>
+
+            <ImageView
+                android:layout_width="match_parent"
+                android:layout_weight="1"
+                android:layout_height="40dp"
+                android:layout_marginTop="-40dp"
+                android:background="@drawable/gradient_v_white"
+                android:adjustViewBounds="true"
+                android:contentDescription="@string/empty"
+                tools:ignore="InefficientWeight"/>
+
+        </LinearLayout>
+
+    </LinearLayout>
+
+</LinearLayout>

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

@@ -164,7 +164,7 @@
 	<string name="pop_menu_share">Share</string>
 	<string name="pop_menu_about">About us</string>
 	<string name="pop_menu_settings">Settings</string>
-	<string name="pop_menu_sponsors">-</string>
+	<string name="pop_menu_sponsors">Sponsors</string>
 	<string name="preferences">Preferences</string>
 	<string name="preferences_info">Information</string>
 	<string name="preferences_info_feedback">Feedback</string>

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

@@ -169,7 +169,7 @@
 	<string name="pop_menu_share">Bitarte</string>
 	<string name="pop_menu_about">Gu</string>
 	<string name="pop_menu_settings">Ajustes</string>
-	<string name="pop_menu_sponsors">-</string>
+	<string name="pop_menu_sponsors">Patrocinadores</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 - 3
app/src/main/res/values/strings.xml

@@ -182,7 +182,9 @@
 
 	<!-- Pop-up menu entry strings -->
 	<string name="pop_menu_settings">Ajustes</string>
-	<string name="pop_menu_sponsors">Sponsors</string>
+	<string name="pop_menu_share">Compartir</string>
+	<string name="pop_menu_sponsors">Patrocinadores</string>
+	<string name="pop_menu_about">Sobre nosotros</string>
 
 	<!--Preferences screen-->
 	<string name="preferences">Preferencias</string>
@@ -214,8 +216,6 @@
 	<string name="eur" translatable="false">€</string>
 	<string name="Kb" translatable="false"> Kb</string>
 	<string name="Mb" translatable="false"> Mb</string>
-	<string name="pop_menu_share">Compartir</string>
-	<string name="pop_menu_about">Sobre nosotros</string>
 	<string name="preferences_info_source">Código fuente</string>
 	<string name="changelog">Changelog</string>
 	<string name="empty" translatable="false"> </string>

+ 1 - 1
build.gradle

@@ -4,7 +4,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.2.2'
+        classpath 'com.android.tools.build:gradle:2.2.3'
     }
 }