This GitLab instance reached the end of its service life. It won't be possible to create new users or projects.

Please read the deprecation notice for more information concerning the deprecation timeline

Visit migration.git.tu-berlin.de (internal network only) to import your old projects to the new GitLab platform 📥

Commit 076be031 by Andrew Karpow

major refactoring, network based on android volley, swipe-to-update,

minor visual improovments
parent b127ba57
......@@ -31,6 +31,6 @@ android {
}
dependencies {
compile 'com.android.support:support-v4:22.0.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:support-v4:22.0.+'
compile 'com.mcxiaoke.volley:library-aar:1.0.+'
}
......@@ -3,12 +3,8 @@ package de.k4ever.k4android;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import de.k4ever.k4android.utils.BalancePager;
public class BalanceActivity extends FragmentActivity {
@Override
......@@ -18,10 +14,6 @@ public class BalanceActivity extends FragmentActivity {
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.fragment_balance);
BalancePager adapter = new BalancePager(this);
ViewPager pager = (ViewPager)findViewById(R.id.pager_balance);
pager.setAdapter(adapter);
}
@Override
......
package de.k4ever.k4android;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.MenuItem;
import de.k4ever.k4android.database.KassenContentProvider;
import de.k4ever.k4android.database.KassenSQLiteHelper.Products;
import de.k4ever.k4android.fragments.BuyScreenFragment;
public class BuyScreenActivity extends Activity {
public class BuyScreenActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -35,7 +35,7 @@ public class BuyScreenActivity extends Activity {
Products.COLUMNS_ALL, null, null, null);
cursor.moveToFirst();
BuyScreenFragment kaufscreen = (BuyScreenFragment) getFragmentManager()
BuyScreenFragment kaufscreen = (BuyScreenFragment)getSupportFragmentManager()
.findFragmentById(R.id.fragment_buyscreen);
kaufscreen.showProdukt(cursor);
}
......
package de.k4ever.k4android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.MenuItem;
import android.view.Window;
public class HistoryListActivity extends Activity {
public class HistoryListActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.fragment_history_list);
......
package de.k4ever.k4android;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
public class ProdukteActivity extends Activity {
public class ProdukteActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
//requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.fragment_produkte);
}
......
......@@ -3,10 +3,8 @@ package de.k4ever.k4android;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;
import android.view.Window;
import de.k4ever.k4android.utils.VirtualsPager;
public class VirtualsActivity extends FragmentActivity {
......@@ -17,11 +15,6 @@ public class VirtualsActivity extends FragmentActivity {
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.fragment_virtuals);
if (findViewById(R.id.fragment_virtuals_list) == null) {
VirtualsPager adapter = new VirtualsPager(this);
ViewPager pager = (ViewPager)findViewById(R.id.pager_virtuals);
pager.setAdapter( adapter );
}
}
@Override
......
package de.k4ever.k4android.fragments;
import java.util.ArrayList;
import java.util.Map;
import android.graphics.Bitmap;
import android.support.v4.app.Fragment;
import android.util.Log;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
......@@ -11,12 +11,10 @@ import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.NetworkImageView;
import de.k4ever.k4android.utils.KassenHttpUtils;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.database.Cursor;
......@@ -46,7 +44,7 @@ import de.k4ever.k4android.database.KassenSQLiteHelper;
import de.k4ever.k4android.database.KassenSQLiteHelper.Products;
import de.k4ever.k4android.utils.KassenConfig;
public class BuyScreenFragment extends Fragment
public class BuyScreenFragment extends Fragment
implements SeekBar.OnSeekBarChangeListener, OnItemSelectedListener {
private int mItemID, mMultiplier;
private TextView mPrice, mDeposit, mNumItems, mDescText, mName;
......
......@@ -4,17 +4,12 @@ import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import android.app.Activity;
import android.app.ListFragment;
import android.app.LoaderManager;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.SimpleCursorAdapter;
......@@ -27,20 +22,17 @@ import de.k4ever.k4android.database.KassenSQLiteHelper.Products;
import de.k4ever.k4android.database.KassenUpdateDatasets;
import de.k4ever.k4android.database.KassenUpdateDatasets.RequestType;
public class HistoryListFragment extends ListFragment
public class HistoryListFragment extends SwipeRefreshListFragment
implements LoaderManager.LoaderCallbacks<Cursor> {
final private static int LOADER_HISTORY = -1;
final private static int LOADER_PRODUCTS = 2;
private Cursor mProductCursor = null;
private SimpleCursorAdapter mAdapter;
private Boolean mUpdateInProgress;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUpdateInProgress = false;
setHasOptionsMenu(true);
}
private void putProducts(LinearLayout v, String items) {
......@@ -65,12 +57,6 @@ implements LoaderManager.LoaderCallbacks<Cursor> {
titleView.setText(title);
v.addView(child);
//Bundle bundle = new Bundle();
//final String[] ids = {cursor.getString(columnIndex)};
//bundle.putParcelable("bla", view);
//bundle.putStringArray("ids", ids);
}
}
......@@ -93,71 +79,57 @@ implements LoaderManager.LoaderCallbacks<Cursor> {
mAdapter.setViewBinder(new ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
switch(view.getId()) {
case R.id.datetime:
final long datetime = cursor.getLong(columnIndex);
final String date = DateFormat.
getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.GERMANY).
format(new Date(datetime));
((TextView)view).setText(date);
return true;
case R.id.amount:
final double amount = cursor.getDouble(columnIndex);
((TextView)view).setText(String.format(getString(R.string.currency_format), amount));
return true;
case R.id.products:
if(mProductCursor == null)
switch (view.getId()) {
case R.id.datetime:
final long datetime = cursor.getLong(columnIndex);
final String date = DateFormat.
getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.GERMANY).
format(new Date(datetime));
((TextView) view).setText(date);
return true;
putProducts((LinearLayout)view, cursor.getString(columnIndex));
return true;
default:
return false;
case R.id.amount:
final double amount = cursor.getDouble(columnIndex);
((TextView) view).setText(String.format(getString(R.string.currency_format), amount));
return true;
case R.id.products:
if (mProductCursor == null)
return true;
putProducts((LinearLayout) view, cursor.getString(columnIndex));
return true;
default:
return false;
}
}
});
setListAdapter(mAdapter);
setListShown(false);
getLoaderManager().initLoader(LOADER_HISTORY, null, this);
getLoaderManager().initLoader(LOADER_PRODUCTS, null, this);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem item = menu.add(R.string.update_history);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
item.setIcon(R.drawable.ic_action_refresh);
item.setVisible(!mUpdateInProgress);
item.setOnMenuItemClickListener(new OnMenuItemClickListener() {
setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
mUpdateInProgress = true;
getActivity().invalidateOptionsMenu();
public void onRefresh() {
if (!isRefreshing()) {
setRefreshing(true);
}
new KassenUpdateDatasets(getActivity()) {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mUpdateInProgress = false;
final Activity tmpActivity = getActivity();
if(tmpActivity != null && !tmpActivity.isFinishing())
getActivity().invalidateOptionsMenu();
setRefreshing(false);
}
}.execute(RequestType.HISTORY);
return false;
}
});
if(getActivity() != null)
getActivity().setProgressBarIndeterminateVisibility(mUpdateInProgress);
setListAdapter(mAdapter);
setListShown(false);
getLoaderManager().initLoader(LOADER_HISTORY, null, this);
getLoaderManager().initLoader(LOADER_PRODUCTS, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
public android.support.v4.content.Loader<Cursor> onCreateLoader(int id, Bundle args) {
if(id == LOADER_HISTORY)
return new CursorLoader(getActivity(),
return new CursorLoader(getActivity(),
KassenContentProvider.CONTENT_HISTORY,
null, null, null,
History.COLUMN_DATETIME + " DESC");
......@@ -182,11 +154,6 @@ implements LoaderManager.LoaderCallbacks<Cursor> {
mProductCursor = data;
getListView().invalidate();
//Log.d("bla", loader.getId() + ": " + data.getCount() + " items");
//(()mAdapter.getItem(loader.getId()))
//Log.d("bla", mAdapter.getItem(loader.getId()) + "");
}
}
......
package de.k4ever.k4android.fragments;
import android.app.DialogFragment;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.util.Patterns;
import android.view.KeyEvent;
......@@ -25,15 +24,11 @@ import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import de.k4ever.k4android.R;
import de.k4ever.k4android.database.KassenContentProvider;
import de.k4ever.k4android.database.KassenSQLiteHelper;
import de.k4ever.k4android.utils.KassenConfig;
import de.k4ever.k4android.utils.KassenHttpUtils;
import de.k4ever.k4android.utils.KassenUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Map;
......@@ -57,7 +52,7 @@ public class LoginFragment extends DialogFragment implements OnEditorActionListe
getActivity()).getString("pref_username", ""));
mServerURL = (EditText) v.findViewById(R.id.apiurl);
mServerURL.setText(PreferenceManager.getDefaultSharedPreferences(
getActivity()).getString("pref_apiurl", ""));
getActivity()).getString("pref_url", ""));
mPassword = (EditText) v.findViewById(R.id.password);
mPassword.setOnEditorActionListener(this);
mPassword.setText(PreferenceManager.getDefaultSharedPreferences(
......@@ -121,11 +116,8 @@ public class LoginFragment extends DialogFragment implements OnEditorActionListe
if (!k4everUrl.startsWith("http"))
k4everUrl = "http://" + k4everUrl;
final String k4everApiUrl = k4everUrl + KassenConfig.KASSEN_SUBDIR_API;
final Editor prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
prefs.putString("pref_url", k4everUrl);
prefs.putString("pref_apiurl", k4everApiUrl);
prefs.putString("pref_username", mUsername.getText().toString());
prefs.putString("pref_password", mPassword.getText().toString());
prefs.putBoolean("pref_sortorder", true);
......
package de.k4ever.k4android.fragments;
import java.io.IOException;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.util.Log;
import android.widget.*;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
......@@ -15,14 +14,10 @@ import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import de.k4ever.k4android.utils.KassenConfig;
import de.k4ever.k4android.utils.KassenHttpUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
......@@ -31,17 +26,20 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import de.k4ever.k4android.R;
public class ManageBalanceFragment extends Fragment {
Menu balanceMenu;
Spinner balanceSpinner;
EditText mSum;
private Menu balanceMenu;
private Switch withDraw;
private EditText mSum;
private Double mBalance;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBalance = Double.NaN;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
......@@ -50,7 +48,7 @@ public class ManageBalanceFragment extends Fragment {
mSum = (EditText)view.findViewById(R.id.sum);
mSum.setText(String.format("%.2f", 1f));
balanceSpinner = (Spinner)view.findViewById(R.id.chargetype);
withDraw = (Switch)view.findViewById(R.id.switch1);
Button incButton = (Button)view.findViewById(R.id.inc);
Button decButton = (Button)view.findViewById(R.id.dec);
......@@ -64,21 +62,37 @@ public class ManageBalanceFragment extends Fragment {
});
decButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
public void onClick(View v) {
try {
float currentSum = NumberFormat.getInstance().parse(mSum.getText().toString()).floatValue();
float currentSum = NumberFormat.getInstance().parse(mSum.getText().toString()).floatValue();
if (currentSum > 1) {
mSum.setText(String.format("%.2f", currentSum - 1f));
}
} catch (ParseException e) {}
}
mSum.setText(String.format("%.2f", currentSum - 1f));
}
} catch (ParseException e) {
}
}
});
setHasOptionsMenu(true);
updateBalance();
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.balance_menu, menu);
balanceMenu = menu;
if(!Double.isNaN(mBalance))
balanceMenu
.findItem(R.id.menu_balance)
.setTitle(getString(
R.string.balance_value,
getString(R.string.currency_format, mBalance)
));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_balance_send:
......@@ -107,16 +121,26 @@ public class ManageBalanceFragment extends Fragment {
}
else {
// amount * -1 to withdraw
if (balanceSpinner.getSelectedItemId() == 1)
if (withDraw.isChecked())
amount *= -1;
final ProgressDialog dialog = ProgressDialog.show(getActivity(), "",
getString(R.string.please_wait), true);
String url = KassenHttpUtils.getUrl(KassenConfig.KASSEN_SUBDIR_TRANSACTIONS, getActivity());
JSONObject balanceObj = null;
try {
balanceObj = new JSONObject();
balanceObj.put("amount", Float.toString(amount));
balanceObj.put("type", 1);
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest request = new JsonObjectRequest(
Request.Method.POST,
url,
null,
balanceObj,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject kassenObj) {
......@@ -129,39 +153,24 @@ public class ManageBalanceFragment extends Fragment {
public void onErrorResponse(VolleyError volleyError) {
dialog.dismiss();
Log.e("Volley", "Error: " + volleyError.toString());
Toast.makeText(getActivity(), volleyError.getLocalizedMessage(), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), volleyError.toString(), Toast.LENGTH_LONG).show();
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> map = KassenHttpUtils
return KassenHttpUtils
.getAuthHeader(getActivity());
NumberFormat numFormat = NumberFormat.getInstance();
float amount = 0;
try {
amount = numFormat.parse(mSum.getText().toString()).floatValue();
} catch (ParseException e) {
e.printStackTrace();
}
map.put("amount", Float.toString(amount));
map.put("type", "1");
return map;
}
};
dialog.show();
KassenHttpUtils.getInstance(getActivity()).addToRequestQueue(request);
}
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.balance_menu, menu);
balanceMenu = menu;
updateBalance();
}
private void updateBalance() {
getActivity().invalidateOptionsMenu();
String url = KassenHttpUtils.getUrl(KassenConfig.KASSEN_SUBDIR_BALANCE, getActivity());
JsonObjectRequest request = new JsonObjectRequest(
Request.Method.GET,
......@@ -170,25 +179,22 @@ public class ManageBalanceFragment extends Fragment {
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject result) {
try {
if (balanceMenu != null && balanceMenu.findItem(R.id.menu_balance) != null)
balanceMenu
.findItem(R.id.menu_balance)
.setTitle(getString(
R.string.balance_value,
getString(R.string.currency_format, result.getDouble("balance"))
));
} catch (JSONException e) {
e.printStackTrace();
}
try {
mBalance = result.getDouble("balance");
final Activity tmpActivity = getActivity();
if (tmpActivity != null && !tmpActivity.isFinishing())
getActivity().invalidateOptionsMenu();
} catch (JSONException e) {
e.printStackTrace();
} catch(IllegalStateException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Log.e("Volley", "Error: " + volleyError.toString());
Toast.makeText(getActivity(), volleyError.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}
) {
......
package de.k4ever.k4android.fragments;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.widget.SwipeRefreshLayout;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
......@@ -9,16 +15,8 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ListFragment;
import android.app.LoaderManager;
import android.app.ProgressDialog;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
......@@ -44,16 +42,14 @@ import de.k4ever.k4android.utils.KassenConfig;
import de.k4ever.k4android.utils.KassenListeAdapter;
import de.k4ever.k4android.utils.KassenUtils;
public class ProdukteFragment extends ListFragment
public class ProdukteFragment extends SwipeRefreshListFragment
implements LoaderManager.LoaderCallbacks<Cursor> {
private KassenListeAdapter mAdapter;
protected Boolean mReady = true;
protected Boolean mUpdateInProgress;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUpdateInProgress = false;
}
@Override
......@@ -65,8 +61,6 @@ public class ProdukteFragment extends ListFragment
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.produkte_menu, menu);
menu.findItem(R.id.menu_refresh).setVisible(!mUpdateInProgress);
getActivity().setProgressBarIndeterminateVisibility(mUpdateInProgress);
}
@Override
......@@ -74,22 +68,6 @@ public class ProdukteFragment extends ListFragment
Intent intent;
switch(item.getItemId()) {
case R.id.menu_refresh:
mUpdateInProgress = true;
getActivity().invalidateOptionsMenu();
new KassenUpdateDatasets(getActivity()) {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mUpdateInProgress = false;
final Activity tmpActivity = getActivity();
if(tmpActivity != null && !tmpActivity.isFinishing())
getActivity().invalidateOptionsMenu();
}
}.execute(RequestType.PRODUCTS);