|
@@ -1,26 +1,35 @@
|
|
|
package com.ivalentin.margolariak;
|
|
package com.ivalentin.margolariak;
|
|
|
|
|
|
|
|
|
|
+import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
|
-import android.content.Context;
|
|
|
|
|
|
|
+import android.app.Dialog;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
import android.database.Cursor;
|
|
import android.database.Cursor;
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.BitmapFactory;
|
|
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
-import android.util.Log;
|
|
|
|
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.view.Window;
|
|
import android.view.Window;
|
|
|
|
|
+import android.view.WindowManager;
|
|
|
|
|
+import android.widget.Button;
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
|
-import android.widget.RelativeLayout;
|
|
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
import java.io.File;
|
|
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 {
|
|
public class SponsorActivity extends Activity {
|
|
|
|
|
|
|
@@ -30,6 +39,7 @@ public class SponsorActivity extends Activity {
|
|
|
* @param savedInstanceState Saved state of the activity.
|
|
* @param savedInstanceState Saved state of the activity.
|
|
|
* @see Activity#onCreate(Bundle)
|
|
* @see Activity#onCreate(Bundle)
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @SuppressLint("InflateParams")
|
|
|
@Override
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
@@ -56,12 +66,16 @@ public class SponsorActivity extends Activity {
|
|
|
//Create a new row
|
|
//Create a new row
|
|
|
entry = (LinearLayout) factory.inflate(R.layout.row_sponsor, null);
|
|
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);
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
int margin = (int) (9 * getResources().getDisplayMetrics().density);
|
|
int margin = (int) (9 * getResources().getDisplayMetrics().density);
|
|
|
layoutParams.setMargins(margin, margin, margin, margin);
|
|
layoutParams.setMargins(margin, margin, margin, margin);
|
|
|
entry.setLayoutParams(layoutParams);
|
|
entry.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
|
|
+ //Set id (hidden)
|
|
|
|
|
+ TextView tvId = (TextView) entry.findViewById(R.id.tv_row_sponsor_id);
|
|
|
|
|
+ tvId.setText(cursor.getString(0));
|
|
|
|
|
+
|
|
|
//Set title
|
|
//Set title
|
|
|
TextView tvTitle = (TextView) entry.findViewById(R.id.tv_row_sponsor_name);
|
|
TextView tvTitle = (TextView) entry.findViewById(R.id.tv_row_sponsor_name);
|
|
|
tvTitle.setText(cursor.getString(1));
|
|
tvTitle.setText(cursor.getString(1));
|
|
@@ -73,7 +87,7 @@ public class SponsorActivity extends Activity {
|
|
|
//Set image
|
|
//Set image
|
|
|
ImageView ivImage = (ImageView) entry.findViewById(R.id.iv_row_sponsor_image);
|
|
ImageView ivImage = (ImageView) entry.findViewById(R.id.iv_row_sponsor_image);
|
|
|
//Check if image exists
|
|
//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);
|
|
String image = cursor.getString(3);
|
|
|
File f;
|
|
File f;
|
|
|
f = new File(getFilesDir().toString() + "/img/spo/preview/" + image);
|
|
f = new File(getFilesDir().toString() + "/img/spo/preview/" + image);
|
|
@@ -94,9 +108,15 @@ public class SponsorActivity extends Activity {
|
|
|
ivImage.setVisibility(View.GONE);
|
|
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);
|
|
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.
|
|
* Not called from code, but referenced from activity_sponsor.xml.
|