Back to project page SeeKampf.
The source code is released under:
GNU General Public License
If you think the Android project SeeKampf listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.avedo.seekampf.fragments; //from w w w . j av a 2s.c o m import net.avedo.seekampf.R; import net.avedo.seekampf.R.drawable; import net.avedo.seekampf.R.id; import net.avedo.seekampf.R.layout; import net.avedo.seekampf.R.string; import net.avedo.seekampf.core.CustomAdapter; import net.avedo.seekampf.core.RestDetailsActivity; import net.avedo.seekampf.models.Message; import net.avedo.seekampf.utils.Constants; import android.content.Context; import android.content.Intent; import android.text.Html; import android.text.format.DateFormat; import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import java.text.SimpleDateFormat; public class MessageListFragment extends RestListFragment<Message> { public static final String TAG = "MessageList"; @Override protected String fetchServiceTag() { return TAG; } @Override protected void fetchServiceAdapter(Message[] messages) { adapter = new MessageAdapter(getActivity(), R.layout.message_row, messages); } @Override protected Class<Message[]> fetchServiceObjClass() { return Message[].class; } @Override protected String fetchServiceUrl() { return "https://www.seekampf.de/api/api2.php?server=" + settings.getString(res.getString(R.string.prefs_server_key), "1") + "&typ=nachrichten&orderby=time&dir=desc"; } @Override public void onListItemClick(ListView list, View view, int position, long id) { Intent intent = new Intent(getActivity(), RestDetailsActivity.class); intent.putExtra(Constants.INTENT_EXTRA_ID, id); intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT, Constants.FRAGMENT_MESSAGE_DETAILS); getActivity().startActivity(intent); } private class MessageAdapter extends CustomAdapter<Message> { public MessageAdapter(Context context, int resId, Message[] messages) { super(context, resId, messages); } @Override public View getView(int position, View convertView, ViewGroup parent) { super.getView(position, convertView, parent); if (convertView == null) { // Fetch the layout inflater ... LayoutInflater li = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); // ... and load the message row layout. convertView = li.inflate(R.layout.message_row, null); } // Fetch the current message. Message message = getItem(position); // Fetch the ImageView ... ImageView messageState = (ImageView) convertView.findViewById(R.id.messageState); // ... and initialize it. if(message.getGelesen() != 1) { messageState.setImageResource(R.drawable.message_new); } // Fetch the message sender field ... TextView messageSender = (TextView) convertView.findViewById(R.id.messageSender); // ... and initialize it. messageSender.setText(Html.fromHtml(message.getVon())); // Fetch the message subject field ... TextView messageSubject = (TextView) convertView.findViewById(R.id.messageSubject); // ... and initialize it. messageSubject.setText(message.getBetreff() == null ? "" : Html.fromHtml(message.getBetreff())); // Fetch the message receiving Date field ... TextView receivingDate = (TextView) convertView.findViewById(R.id.receivingDate); // ... and initialize it. if(DateUtils.isToday(message.getTime() * 1000)) { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); receivingDate.setText(sdf.format(message.getTime() * 1000).toString()); } else { SimpleDateFormat sdf = new SimpleDateFormat("d. MMM"); receivingDate.setText(sdf.format(message.getTime() * 1000).toString()); } return convertView; } } }