Created
November 8, 2014 07:15
-
-
Save valokafor/9d085876940cc0212c7a to your computer and use it in GitHub Desktop.
An Android Fragment to display list of upcoming bills
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.valokafor.billduedateazure.Fragments; | |
import android.app.AlertDialog; | |
import android.app.Fragment; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ListView; | |
import com.microsoft.windowsazure.mobileservices.ServiceFilterResponse; | |
import com.microsoft.windowsazure.mobileservices.TableQueryCallback; | |
import com.valokafor.billduedateazure.Adapters.UpcomingBillAdapter; | |
import com.valokafor.billduedateazure.AzureMobileService.BillDueDateService; | |
import com.valokafor.billduedateazure.BillDueDateApplication; | |
import com.valokafor.billduedateazure.Model.Bill; | |
import com.valokafor.billduedateazure.R; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
*/ | |
public class UpcomingBillsFragment extends Fragment { | |
private View mRootView; | |
private final static String TAG = UpcomingBillsFragment.class.getSimpleName(); | |
UpcomingBillAdapter mUpcomingBillAdapter; | |
private ListView upComingBillListView; | |
private List<Bill> listOfBills = new ArrayList<Bill>(); | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
mRootView = inflater.inflate(R.layout.fragment_upcoming_bills, container, false); | |
mUpcomingBillAdapter = new UpcomingBillAdapter(getActivity(), 0, listOfBills); | |
upComingBillListView = (ListView) mRootView.findViewById(R.id.upcoming_bills_listview); | |
upComingBillListView.setAdapter(mUpcomingBillAdapter); | |
refreshUpComingBills(); | |
return mRootView; | |
} | |
private void refreshUpComingBills() { | |
Log.i(TAG, "Calling get data"); | |
BillDueDateApplication myApp = (BillDueDateApplication) getActivity().getApplication(); | |
BillDueDateService mBillDueDateService = myApp.getBillDueDateService(); | |
mBillDueDateService.mBillTable | |
.execute(new TableQueryCallback<Bill>() { | |
@Override | |
public void onCompleted(List<Bill> result, int count, | |
Exception exception, ServiceFilterResponse response) { | |
if (exception == null){ | |
for (Bill bill : result){ | |
long timeInLong = bill.getBillDueDate().getTime(); | |
long currentTime = System.currentTimeMillis(); | |
long diffTime = timeInLong - currentTime; | |
long diffDays = diffTime / (1000 * 60 * 60 * 24); | |
int daysdiff = (int) diffDays; | |
bill.setDaysBeforeDueDate(daysdiff); | |
mUpcomingBillAdapter.add(bill); | |
} | |
} else { | |
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | |
builder.setMessage(exception.getMessage()); | |
builder.setTitle("Error"); | |
builder.create().show(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment