Commit 9be5255c authored by Schoumi's avatar Schoumi

Cleanup on activities and add GPLV3 Header in each source file

parent 60e0a9dd
/*
* Copyright (C) 2015 Anthony Chomienne, anthony@mob-dev.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package fr.mobdev.gobelim.activity;
import android.content.Context;
......@@ -24,19 +42,24 @@ import fr.mobdev.gobelim.Database;
import fr.mobdev.gobelim.objects.Img;
import fr.mobdev.gobelim.R;
/*
* This Activity help user to find old shared pictures and re-share it if he wanted to
*/
public class HistoryActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history);
ListView historyList = (ListView) findViewById(R.id.history_list);
final List<Img> images = Database.getInstance(getApplicationContext()).getHistory();
HistoryAdapter adapter = new HistoryAdapter(this,R.layout.history_item,R.id.url_history_item,images);
historyList.setAdapter(adapter);
historyList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent linkIntent = new Intent(HistoryActivity.this,LinkActivity.class);
......@@ -47,9 +70,11 @@ public class HistoryActivity extends ActionBarActivity {
startActivity(linkIntent);
}
}
});
}
//Adapter to handle History Items
private class HistoryAdapter extends ArrayAdapter<Img>
{
......@@ -59,7 +84,7 @@ public class HistoryActivity extends ActionBarActivity {
public HistoryAdapter(Context context, int resource, int textViewResourceId, List<Img> objects) {
super(context, resource, textViewResourceId, objects);
images = new ArrayList(objects);
images = new ArrayList<>(objects);
this.resource = resource;
mInflater = LayoutInflater.from(context);
}
......@@ -68,10 +93,12 @@ public class HistoryActivity extends ActionBarActivity {
public View getView(int position, View convertView, ViewGroup parent)
{
Img image = images.get(position);
//reuse view or create a new one?
if (convertView == null) {
convertView = mInflater.inflate(resource, parent, false);
}
//display url
TextView urlView = (TextView) convertView.findViewById(R.id.url_history_item);
String url = image.getUrl();
if(!url.endsWith("/"))
......@@ -97,6 +124,7 @@ public class HistoryActivity extends ActionBarActivity {
Calendar today = Calendar.getInstance();
long millis = today.getTimeInMillis() - date.getTimeInMillis();
long days = millis / (24*60*60*1000);
//storage duration has ended or not?
if(storageDuration - days < 0) {
durationView.setText(getString(R.string.duration_ended));
}
......@@ -108,7 +136,7 @@ public class HistoryActivity extends ActionBarActivity {
}
}
//Display miniatures if it exist
ImageView thumb = (ImageView) convertView.findViewById(R.id.thumbnail);
if(image.getThumb() != null)
thumb.setImageBitmap(image.getThumb());
......
/*
* Copyright (C) 2015 Anthony Chomienne, anthony@mob-dev.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package fr.mobdev.gobelim.activity;
import android.content.Intent;
......@@ -12,7 +30,10 @@ import android.widget.Toast;
import fr.mobdev.gobelim.R;
/*
* Activity display the link of the uploaded picture and allow user to share it with other app
* or copy it to cleapboard
*/
public class LinkActivity extends ActionBarActivity {
@Override
......@@ -20,16 +41,19 @@ public class LinkActivity extends ActionBarActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.link);
//get url information
Intent receiveIntent = getIntent();
String url = receiveIntent.getStringExtra("URL");
String shortHash = receiveIntent.getStringExtra("short");
//add a / at the end of the url before adding the hash
if(!url.endsWith("/"))
url = url.concat("/");
url = url.concat(shortHash);
final String sharedUrl = url;
//manage the sharing button
ImageButton shareButton = (ImageButton) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -42,6 +66,7 @@ public class LinkActivity extends ActionBarActivity {
}
});
//manage the clipboard button
ImageButton copyClipboardButton = (ImageButton) findViewById(R.id.copy_clipboard_button);
copyClipboardButton.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -53,6 +78,7 @@ public class LinkActivity extends ActionBarActivity {
}
});
//add the url to the textview
TextView link = (TextView) findViewById(R.id.link);
link.setText(sharedUrl);
}
......
/*
* Copyright (C) 2015 Anthony Chomienne, anthony@mob-dev.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package fr.mobdev.gobelim.activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.provider.ContactsContract;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
......@@ -15,7 +31,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
......@@ -29,7 +44,9 @@ import fr.mobdev.gobelim.listener.ServerListener;
import fr.mobdev.gobelim.objects.Server;
import fr.mobdev.gobelim.R;
/*
* Activity that allow user to manage the server where he want to upload his images. Server must be lutim instance to work with the app
*/
public class ServersActivity extends ActionBarActivity {
private List<Server> dbServers;
......@@ -39,6 +56,7 @@ public class ServersActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.servers);
ListView serverList = (ListView) findViewById(R.id.servers_list);
serverList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
......@@ -54,6 +72,7 @@ public class ServersActivity extends ActionBarActivity {
}
}
Server newDefaultServer = dbServers.get(position);
//if old default server exist or not, make the selected one the new Default
if(oldDefaultServer == null) {
Database.getInstance(getApplicationContext()).setDefaultServer(newDefaultServer.getId(),-1);
}
......@@ -65,20 +84,23 @@ public class ServersActivity extends ActionBarActivity {
}
});
//listener use to manage delete button on each view
listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
ListView serverList = (ListView) findViewById(R.id.servers_list);
//retrieve the position of the server in the list
Integer pos = (Integer)v.getTag();
if(pos == null)
return;
final Server server = dbServers.get(pos.intValue());
//ask delete
//retrieve the server
final Server server = dbServers.get(pos);
//ask for delete to the user
AlertDialog.Builder builder = new AlertDialog.Builder(ServersActivity.this);
builder.setMessage(getString(R.string.delete_server_message)+" "+server.getUrl())
.setCancelable(false)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//delete server from database and update the view
dbServers.remove(server);
Database.getInstance(getApplicationContext()).deleteServer(server.getId());
updateServers();
......@@ -93,11 +115,13 @@ public class ServersActivity extends ActionBarActivity {
alert.show();
}
};
updateServers();
}
private void updateServers()
{
// build the view with server list in database
dbServers = Database.getInstance(getApplicationContext()).getServers(false);
ServerAdapter adapter = new ServerAdapter(this,R.layout.server_item,R.id.server_name,dbServers,listener);
......@@ -133,6 +157,7 @@ public class ServersActivity extends ActionBarActivity {
return super.onOptionsItemSelected(item);
}
//adapter for the server list
private class ServerAdapter extends ArrayAdapter<Server>
{
......@@ -143,7 +168,7 @@ public class ServersActivity extends ActionBarActivity {
public ServerAdapter(Context context, int resource, int textViewResourceId, List<Server> objects, View.OnClickListener listener) {
super(context, resource, textViewResourceId, objects);
servers = new ArrayList(objects);
servers = new ArrayList<>(objects);
this.listener = listener;
this.resource = resource;
mInflater = LayoutInflater.from(context);
......@@ -152,11 +177,14 @@ public class ServersActivity extends ActionBarActivity {
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
//get the server
Server server = servers.get(position);
//create a new view or reuse a previous one
if (convertView == null) {
convertView = mInflater.inflate(resource, parent, false);
}
//setup the server url view
TextView view = (TextView) convertView.findViewById(R.id.server_name);
if(server.isDefaultServer()) {
Typeface typeface = view.getTypeface();
......@@ -165,9 +193,10 @@ public class ServersActivity extends ActionBarActivity {
}
view.setText(server.getUrl());
//setup the delete button view
ImageView delete = (ImageView) convertView.findViewById(R.id.server_delete);
delete.setOnClickListener(listener);
delete.setTag(Integer.valueOf(position));
delete.setTag(position);
return convertView;
}
......
......@@ -18,7 +18,8 @@
<TextView
android:textColor="#FF0000"
android:id="@+id/duration"
android:layout_width="wrap_content"
android:gravity="right"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
......
......@@ -17,11 +17,11 @@
<string name="show_history">Voir l\'historique</string>
<string name="delete_server_message">Supprimer le server</string>
<string name="upload_progress">Envoi en cours</string>
<string name="no_duration"></string>
<string name="no_duration">\u221E</string>
<string name="duration_ended">Supprimée</string>
<string name="days">Jours restants</string>
<string name="day">Jour restant</string>
<string name="server_list_error">Vous n\t fetch'avez aucun serveur configuré, merci d\'en ajouter un</string>
<string name="server_list_error">Vous n\'avez aucun serveur configuré, merci d\'en ajouter un</string>
<string-array name="deleted_days">
<item>Pas de limitation</item>
<item>24 Heures</item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment