Browse Source

Cleanup on activities and add GPLV3 Header in each source file

tags/release_v1
Schoumi 4 years ago
parent
commit
9be5255cdc

+ 32
- 4
app/src/main/java/fr/mobdev/gobelim/activity/HistoryActivity.java View File

@@ -1,3 +1,21 @@
/*
* 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());

+ 27
- 1
app/src/main/java/fr/mobdev/gobelim/activity/LinkActivity.java View File

@@ -1,3 +1,21 @@
/*
* 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);
}

+ 49
- 56
app/src/main/java/fr/mobdev/gobelim/activity/MainActivity.java View File

@@ -52,6 +52,12 @@ import fr.mobdev.gobelim.objects.Img;
import fr.mobdev.gobelim.objects.Server;
import fr.mobdev.gobelim.R;

/*
* Activity used to handle sharing pictures from other app that user want to upload on a lutim instance
* if user launch the app by itself he can also pick a pictures from his device and upload it as well.
* This Activity let user access to the others activities in order to manage history, servers and after an upload
* the shared options of the given link
*/
public class MainActivity extends ActionBarActivity {

private NetworkListener listener;
@@ -60,7 +66,9 @@ public class MainActivity extends ActionBarActivity {
private List<String> urls;
private List<Integer> deletedDays;
private ProgressDialog progressDialog;
private String filePath;

//static value to handle storage durations options
private static final int NEVER = 0;
private static final int ONE = 1;
private static final int SEVEN = 7;
@@ -72,6 +80,7 @@ public class MainActivity extends ActionBarActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//prepare data used for upload
imageUri = null;
urls = new ArrayList<>();
deletedDays = new ArrayList<>();
@@ -82,6 +91,8 @@ public class MainActivity extends ActionBarActivity {
deletedDays.add(YEAR);

updateServerList();

//retrieve previous state if it exist
if(savedInstanceState != null) {
int selectedServer = savedInstanceState.getInt("selectedServer");
imageUri = savedInstanceState.getParcelable("imageURI");
@@ -89,8 +100,10 @@ public class MainActivity extends ActionBarActivity {
Spinner servers = (Spinner) findViewById(R.id.servers_spinner);
servers.setSelection(selectedServer);
}
displayImage();
}

//prepare the listener that handle upload result
listener = new NetworkListener() {
@Override
public void fileUploaded(final Img image) {
@@ -100,7 +113,8 @@ public class MainActivity extends ActionBarActivity {
//add uploaded img to history
Database.getInstance(getApplicationContext()).addImage(image);
//dismiss progressDialog
progressDialog.dismiss();
if(progressDialog!=null)
progressDialog.dismiss();
//launch LinkActivity
Intent linkIntent = new Intent(MainActivity.this,LinkActivity.class);
linkIntent.putExtra("URL", image.getUrl());
@@ -117,12 +131,14 @@ public class MainActivity extends ActionBarActivity {
public void run() {
//display toast error
Toast.makeText(MainActivity.this, error, Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
if(progressDialog != null)
progressDialog.dismiss();
}
});
}
};

//prepare for upload
Button uploadBt = (Button) findViewById(R.id.upload_button);
uploadBt.setOnClickListener(new View.OnClickListener() {
@Override
@@ -141,14 +157,16 @@ public class MainActivity extends ActionBarActivity {
}
});

//have we receive image from share or do you need to ask it to the user
//have we receive image from share or do you need to ask it to the user if we haven't ask for it before (screen rotation)
Intent receiveIntent = getIntent();
if(receiveIntent == null || receiveIntent.getType() == null || !receiveIntent.getType().contains("image/")) {
if((receiveIntent == null || receiveIntent.getType() == null || !receiveIntent.getType().contains("image/")) && imageUri == null) {
uploadBt.setVisibility(View.GONE);
}
else {
selectBt.setVisibility(View.GONE);
imageUri = receiveIntent.getParcelableExtra(Intent.EXTRA_STREAM);
if(receiveIntent != null && imageUri == null) {
imageUri = receiveIntent.getParcelableExtra(Intent.EXTRA_STREAM);
}
displayImage();
}
}
@@ -162,6 +180,7 @@ public class MainActivity extends ActionBarActivity {

@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
//save imageURI and selected server position
savedInstanceState.putParcelable("imageURI", imageUri);
Spinner selectedServer = (Spinner) findViewById(R.id.servers_spinner);
int pos = selectedServer.getSelectedItemPosition();
@@ -171,11 +190,13 @@ public class MainActivity extends ActionBarActivity {

private void updateServerList() {
Spinner serversSpinner = (Spinner) findViewById(R.id.servers_spinner);
//retrieve the selected server name in case it change his place in list
String selectedServer = (String) serversSpinner.getSelectedItem();

List<Server> servers = Database.getInstance(getApplicationContext()).getServers(true);
urls.clear();
int pos = 0;
//create the string list of server name from database data
for(Server server : servers) {
if(server.getUrl().equals(selectedServer)) {
pos = urls.size();
@@ -186,53 +207,22 @@ public class MainActivity extends ActionBarActivity {
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,android.R.layout.simple_dropdown_item_1line,urls);
serversSpinner.setAdapter(adapter);

//select the previous selected server
serversSpinner.setSelection(pos);
}

private void displayImage() {
FileInputStream fileStream = null;
File file;
if(imageUri != null) {
//retrieve the filePath of the image
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(imageUri, null, null, null, null);
cursor.moveToFirst();
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
cursor.close();
file = new File(filePath);
fileName = file.getName();
try {
fileStream = new FileInputStream(file);

} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
if(fileStream != null) {
try {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
int readed = 0;
byte[] buffer = new byte[1024];
while(readed != -1) {
try {
readed = fileStream.read(buffer);
if(readed != -1)
outStream.write(buffer,0,readed);
} catch (IOException e) {
e.printStackTrace();
readed = -1;
}
}
byte[] bytearray = outStream.toByteArray();


Bitmap bt = BitmapFactory.decodeByteArray(bytearray,0,bytearray.length);
ImageView view = (ImageView) findViewById(R.id.thumbnail_main);
view.setImageBitmap(bt);
}
catch (Exception e)
{
e.printStackTrace();
}
//display it in the imageView
Bitmap bt = BitmapFactory.decodeFile(filePath);
ImageView view = (ImageView) findViewById(R.id.thumbnail_main);
view.setImageBitmap(bt);
}
}

@@ -246,18 +236,16 @@ public class MainActivity extends ActionBarActivity {
}
String url = urls.get(pos);

//How long the server need to store image
Spinner deleteSpinner = (Spinner)findViewById(R.id.delete_day_spinner);
pos = deleteSpinner.getSelectedItemPosition();
int delete = deletedDays.get(pos);

//read image as bytes to upload it
byte[] bytearray = null;
FileInputStream fileStream = null;
if(imageUri != null) {
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(imageUri, null, null, null, null);
cursor.moveToFirst();
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
cursor.close();
//create a fileStream from the file path
if(filePath != null && !filePath.isEmpty()) {
File file = new File(filePath);
fileName = file.getName();
try {
@@ -267,6 +255,7 @@ public class MainActivity extends ActionBarActivity {
e.printStackTrace();
}
}
//read data from the file and store it in a byte array
if(fileStream != null) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
int readed = 0;
@@ -283,6 +272,7 @@ public class MainActivity extends ActionBarActivity {
}
bytearray = outStream.toByteArray();
}
//upload image and display a progress bar
if(bytearray != null && bytearray.length > 0) {
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage(getString(R.string.upload_progress));
@@ -296,6 +286,7 @@ public class MainActivity extends ActionBarActivity {
}

protected void requestFile() {
//ask for image file
Intent requestFileIntent = new Intent(Intent.ACTION_PICK);
requestFileIntent.setType("image/*");
startActivityForResult(requestFileIntent, 0);
@@ -304,6 +295,7 @@ public class MainActivity extends ActionBarActivity {
@Override
public void onActivityResult(int requestCode, int resultCode,Intent returnIntent) {
if(resultCode == RESULT_OK){
//retrieve uri from the request image activity and prepare
imageUri = returnIntent.getData();
Button uploadBt = (Button) findViewById(R.id.upload_button);
uploadBt.setVisibility(View.VISIBLE);
@@ -323,18 +315,19 @@ public class MainActivity extends ActionBarActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
Intent newIntent = null;
if (id == R.id.action_manage_server) {
Intent serverIntent = new Intent(this,ServersActivity.class);
startActivity(serverIntent);
return true;
newIntent = new Intent(this,ServersActivity.class);
}
else if (id == R.id.action_show_history){
Intent historyIntent = new Intent(this,HistoryActivity.class);
startActivity(historyIntent);
newIntent = new Intent(this,HistoryActivity.class);
}
if(newIntent != null)
{
startActivity(newIntent);
return true;
}

return super.onOptionsItemSelected(item);
}
}
}

+ 38
- 9
app/src/main/java/fr/mobdev/gobelim/activity/ServersActivity.java View File

@@ -1,11 +1,27 @@
/*
* 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;
}

+ 2
- 1
app/src/main/res/layout/history_item.xml View File

@@ -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>


+ 2
- 2
app/src/main/res/values/strings.xml View File

@@ -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>

Loading…
Cancel
Save