zack.yovel.clear.controller.foreground.HourlyFragment.java Source code

Java tutorial

Introduction

Here is the source code for zack.yovel.clear.controller.foreground.HourlyFragment.java

Source

/*
 * Copyright (c) 2014 Yehezkel (Zack) Yovel
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package zack.yovel.clear.controller.foreground;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;

import java.util.List;

import zack.yovel.clear.R;
import zack.yovel.clear.infrastructure.model.datapoints.DataBlock;
import zack.yovel.clear.infrastructure.model.datapoints.DataPoint;
import zack.yovel.clear.infrastructure.model.datapoints.WeatherReport;

public class HourlyFragment extends WeatherFragment {

    public static final int FLAG = 48;
    private static final String TAG = "HourlyFragment";
    private DateTimeFormatter dateTimeFormatter;

    public HourlyFragment() {
        dateTimeFormatter = getDateTimeFormatter();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_forecast, container, false);
        view.findViewById(R.id.listView).setTag(TAG);

        ListView listView = (ListView) view.findViewById(R.id.listView);
        listView.setSelector(R.drawable.transparent);

        return view;
    }

    @Override
    protected void displayWeatherReport(WeatherReport weatherReport) {
        DataBlock hourly = weatherReport.getHourly();
        List<DataPoint> dataPoints = hourly.getData();
        View view = getView();
        ListView listView = (ListView) view.findViewWithTag(TAG);
        TextView emptyView = (TextView) getActivity().findViewById(android.R.id.empty);
        emptyView.setText(R.string.text_hourly_loading);
        listView.setEmptyView(emptyView);
        DataPointAdapter adapter = new DataPointAdapter(getActivity(), dataPoints, dateTimeFormatter, FLAG);
        listView.setAdapter(adapter);
    }

    private DateTimeFormatter getDateTimeFormatter() {
        DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
        builder.appendDayOfWeekShortText().appendLiteral(' ').appendHourOfDay(1).appendLiteral(':')
                .appendMinuteOfHour(2);
        return builder.toFormatter();
    }

}