/*
 * Copyright (C) 2009 Johan Nilsson <http://markupartist.com>
 *
 * 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 com.markupartist.sthlmtraveling;

import android.app.NotificationManager;
import android.net.Uri;
import android.os.Bundle;
import android.text.format.Time;
import android.util.Log;
import android.widget.TextView;

import com.markupartist.sthlmtraveling.provider.deviation.Deviation;


public class DeviationDetailActivity extends BaseActivity {
    static String TAG = "DeviationDetailActivity";
    //public static final String EXTRA_DEVIATION_NOTIFICATION_ID = "com.markupartist.sthlmtraveling.deviation.notificationId";
    //public static final String EXTRA_DEVIATION = "com.markupartist.sthlmtraveling.deviation";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.deviations_row);

        Log.d(TAG, "details!?");
        
        /*Bundle extras = getIntent().getExtras();
        Deviation deviation = extras.getParcelable(EXTRA_DEVIATION);
        if (extras.containsKey(EXTRA_DEVIATION_NOTIFICATION_ID)) {
            int notificationId = extras.getInt(EXTRA_DEVIATION_NOTIFICATION_ID);
            NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
            mNotificationManager.cancel(notificationId);
        }*/

        final Uri uri = getIntent().getData();
        String header = uri.getQueryParameter("header");
        String details = uri.getQueryParameter("details");
        String scope = uri.getQueryParameter("scope");
        String reference = uri.getQueryParameter("reference");
        Time created = new Time();
        created.parse3339(uri.getQueryParameter("created"));
        int notificationId = Integer.parseInt(uri.getQueryParameter("notificationId"));

        TextView headerView = (TextView) findViewById(R.id.deviation_header);
        headerView.setText(header);
        TextView detailsView = (TextView) findViewById(R.id.deviation_details);
        detailsView.setText(details);
        TextView createdView = (TextView) findViewById(R.id.deviation_created);
        createdView.setText(created.format("%F %R"));

        NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        mNotificationManager.cancel(notificationId);
    }

    public static Uri getUri(Deviation deviation, int notificationId) {
        return Uri.parse(String.format("journeyplanner://deviations?"
                + "header=%s"
                + "&details=%s"
                + "&created=%s"
                + "&scope=%s"
                + "&reference=%s"
                + "&notificationId=%s",
                deviation.getHeader(),
                deviation.getDetails(),
                deviation.getCreated().format3339(false),
                deviation.getScope(),
                deviation.getReference(),
                notificationId));
    }
}

@@ -845,16 +845,60 @@
 tView;%0A%0A
+import com.crashlytics.android.Crashlytics;%0A
 import c
@@ -1074,231 +1074,8 @@
 ty%22;
-%0A    //public static final String EXTRA_DEVIATION_NOTIFICATION_ID = %22com.markupartist.sthlmtraveling.deviation.notificationId%22;%0A    //public static final String EXTRA_DEVIATION = %22com.markupartist.sthlmtraveling.deviation%22;
 %0A%0A  
@@ -1270,24 +1270,16 @@
 ls!?%22);%0A
-        
 %0A       
@@ -1283,23 +1283,21 @@
     
-/*Bundle extras
+final Uri uri
  = g
@@ -1314,150 +1314,39 @@
 .get
-Extras();%0A        Deviation deviation = extras.getParcelable(EXTRA_DEVIATION);%0A        if (extras.containsKey(EXTRA_DEVIATION_NOTIFICATION_ID)
+Data();%0A        if (uri == null
 ) %7B%0A
@@ -1361,74 +1361,71 @@
     
-in
+Log.e(TAG, %22No
 t 
+e
 no
-tificationId = extras.getInt(EXTRA_DEVIATION_NOTIFICATION_ID
+ugh data was passed, finish was we started.%22
 );%0A 
@@ -1582,86 +1582,86 @@
 ncel
-(notificationId);%0A        %7D*/%0A%0A        final Uri uri = getIntent().getData();%0A
+All();%0A            finish();%0A            return;%0A        %7D%0A%0A        try %7B%0A    
     
@@ -1717,24 +1717,28 @@
 %22);%0A        
+   
+ 
 String detai
@@ -1780,24 +1780,28 @@
 %22);%0A        
+    
 String scope
@@ -1839,24 +1839,28 @@
 %22);%0A        
+ 
+   
 String refer
@@ -1910,16 +1910,20 @@
         
+   
+ 
 Time cre
@@ -1937,24 +1937,28 @@
 new Time();%0A
+    
         crea
@@ -2014,16 +2014,20 @@
         
+ 
+   
 int noti
@@ -2099,32 +2099,36 @@
 Id%22));%0A%0A        
+   
+ 
 TextView headerV
@@ -2189,16 +2189,20 @@
         
+    
 headerVi
@@ -2221,32 +2221,36 @@
 eader);%0A        
+ 
+   
 TextView details
@@ -2313,16 +2313,20 @@
         
+   
+ 
 detailsV
@@ -2339,32 +2339,36 @@
 tText(details);%0A
+    
         TextView
@@ -2435,24 +2435,28 @@
 d);%0A        
+ 
+   
 createdView.
@@ -2490,32 +2490,36 @@
 %25R%22));%0A%0A        
+   
+ 
 NotificationMana
@@ -2606,32 +2606,36 @@
 RVICE);%0A        
+    
 mNotificationMan
@@ -2659,24 +2659,163 @@
 icationId);%0A
+        %7D catch (Exception e) %7B%0A            Crashlytics.log(%22URI: %22 + uri.toString());%0A            Crashlytics.logException(e);%0A        %7D%0A%0A
     %7D%0A%0A    p

Add logging to the deviation detail view